-
-
Notifications
You must be signed in to change notification settings - Fork 3k
DefaultDict of a TypedDict confuses mypy #7217
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
Yeah, it would be nice if all the cases would be supported by mypy. I think that at least case 5 could be easy to support. 2 and 3 might be harder or require more ad hoc changes. And thanks for the detailed report! |
Hello there, any update on this issue? Thank you very much. |
Having a nested function allows us to discontinue the use of the `key` variable which can be useful if multiple sections of unread_counts need to be updated for a message type. It includes type annotation changes such as: * `key` passed into the nested function is typed using TypeVar. * Message has been typed using a TypedDict so that mypy can determine the type of `key`. Note the use of Totality here because stream messages/pms/huddles do not have the same attributes. This change cannot be split into a prior commit because that will require multiple type definitions of the same `key` variable. * An alternate declaration of `messages` in initial_index is necessary due to a mypy bug - python/mypy#7217 - while using TypeDict with defaultdict.
Note the use of Totality here because stream messages/pms/huddles do not have the same attributes. An alternate declaration of `messages` in initial_index is necessary due to a mypy bug - python/mypy#7217 - while using TypeDict with defaultdict.
Note the use of Totality here because stream messages/pms/huddles do not have the same attributes. An alternate declaration of `messages` in initial_index is necessary due to a mypy bug - python/mypy#7217 - while using TypeDict with defaultdict.
Note the use of Totality here because stream messages/pms/huddles do not have the same attributes. An alternate declaration of `messages` in initial_index is necessary due to a mypy bug - python/mypy#7217 - while using TypeDict with defaultdict.
Note the use of Totality here because stream messages/pms/huddles do not have the same attributes. An alternate declaration of `messages` in initial_index is necessary due to a mypy bug - python/mypy#7217 - while using TypeDict with defaultdict.
Note the absence of Totality here because stream messages/pms/huddles do not have the same attributes. An alternate declaration of `messages` in initial_index is necessary due to a mypy bug - python/mypy#7217 - while using TypeDict with defaultdict.
There is no error message for |
I just checked that with my PR #19254 everything except |
Fixes #3832 Fixes #5723 Fixes #17174 Improves #7217 This is a sixth "major" PR toward #7724. Previously access to "static" attributes (like type aliases, class objects) was duplicated in four places: * In `analyze_ref_expr()` * In `determine_type_of_member()` (for modules as subtypes of protocols) * In instance attribute access logic * In class attribute logic Most of these were somewhat incomplete and/or inconsistent, this PR unifies all four (there is still tiny duplication because I decided to limit the number of deferrals, i.e. preserve the existing logic in this respect). Some notable things that are not pure refactoring: * Previously we disabled access to type variables as class attributes. This was inconsistent with plain references and instance attributes that just return `Instance("typing.TypeVar")`. * Instance access plugins were only applied on `TypeInfo`s and `TypeAlias`es, now they are applied always. * Previously arguments kinds were sometimes not correct for TypedDict class objects with non-required keys. * I tweaked `TypeOfAny` in couple places to be more logical.
Hi 👋 ! I have the following test code:
mypy only accepts the definition of 4 and 6. A pic is easy to follow here
mypy output:
Ideally the def of
State3
, justdefaultdict(dict)
, should work, shouldn't it? It is also very surprising that there is a difference between 5 and 6.mypy 0.720
The text was updated successfully, but these errors were encountered: