mypy
mypy copied to clipboard
Star-star syntax not allowed with TypedDict
🐛 Bug Report
This is similar to #6462 and #9335 but with the star-star syntax.
There are cases where mypy could prove the following program type-safe, but currently this is never allowed:
To Reproduce
from typing import TypedDict
class Value(TypedDict):
key1: str
key2: str
const1: Value = {"key1": "foo", "key2": "bar"}
const2: Value = {**const1, "key2": "eggs"}
# ^^^^^^^^
# mypy: Expected TypedDict key to be string literal (10:20)
- Mypy version used: mypy 0.780
- Python version used: 3.8.6
I'm raising the priority of this issue, since it has been requested many times and there have been at least three duplicate issues.
I've just given this issue a go in my pull request: https://github.com/python/mypy/pull/13353