-
-
Notifications
You must be signed in to change notification settings - Fork 3k
TypedDict keys(), items(), and values() #7845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Mypy is behaving as designed, since TypedDicts support structural subtyping. The type |
@JukkaL how do you justify AbstractSet instead of KeysView/ItemsView? |
@JukkaL adding the from typing_extensions import final, TypedDict
@final
class C(TypedDict):
x: float
y: int
z: str
c: C
reveal_type(c.keys())
reveal_type(c.items())
reveal_type(c.values()) Output:
|
|
Uh oh!
There was an error while loading. Please reload this page.
mypy 0.750+dev.78f2df9d46198563106dd32cb4494678e97d71eb
mypy thinks that the values of a TypedDict yielded by items() or values() are of type object, instead of the Union of all possible values.
As for the keys yielded by keys() or items(), they are upcast to str whereas a Union of Literal would be more precise.
Finally, keys() and items() are incorrectly reported as an AbstractSet instead of KeysView and ItemsView respectively.
Actual output:
Expected output:
The text was updated successfully, but these errors were encountered: