You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the alternative definition syntax for TypedDict (which should be equivalent according to PEP 589), the field names cannot be stored in variables (expected). But, I would expect Final or Literal typed variables to be accepted. See the following example:
$ mypy repro.py
repro.py:8: error: Invalid TypedDict() field name
repro.py:9: error: Extra key 'x'for TypedDict "TypedDict"
repro.py:12: error: Invalid TypedDict() field name
repro.py:13: error: Extra key 'x'for TypedDict "TypedDict"
Found 4 errors in 1 file (checked 1 source file)
What is the behaviour/output you expect?
No errors, or at least one of the two options succeeding (Final or Literal).
The type annotations are equivalent, as far as I can tell.
We have defined constants for the field names of dictionaries read from JSON files. I would like to make TypedDict's for these various dictionaries so that mypy can better check our code (instead of marking all dicts with Dict[str, Any].
I would like to define the fields using these predefined constants.
Bug or opening a feature request?
A bug.
Minimal example
Using the alternative definition syntax for
TypedDict
(which should be equivalent according to PEP 589), the field names cannot be stored in variables (expected). But, I would expectFinal
orLiteral
typed variables to be accepted. See the following example:What is the actual behaviour/output?
What is the behaviour/output you expect?
No errors, or at least one of the two options succeeding (
Final
orLiteral
).The type annotations are equivalent, as far as I can tell.
What are the versions of mypy and Python you are using?
Same behaviour on
master
(ce186f4).Use case
We have defined constants for the field names of dictionaries read from JSON files. I would like to make
TypedDict
's for these various dictionaries so that mypy can better check our code (instead of marking all dicts withDict[str, Any]
.I would like to define the fields using these predefined constants.
The text was updated successfully, but these errors were encountered: