-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
False positive errors with anonymous and inline declaration of namedtuple types #16660
Comments
I'm not sure this should be supported; it's outside the standard type system. |
@JelleZijlstra, what do you mean "outside the standard type system"? This is documented behavior, and there is no theoretical reason why a type checker cannot support it. FWIW, pyright supports it. If you don't want to support it for in mypy because it's infrequently-used and there are other higher-priority issues in the mypy issue tracker, that's understandable, but I don't think "it's outside the standard type system" is a good justification. |
The relevant spec section for TypedDict (https://typing.readthedocs.io/en/latest/spec/typeddict.html#alternative-syntax) only uses the I was going off the analogy with similar type system features like TypeVar, where it was my understanding that the type system required that you use the Surprisingly (to me), though, pyright even allows |
Yeah, pyright enforces name consistency if you assign one of these constructs to an identifier. If you don't assign it to an identifier (e.g. you use it inline), then there's no name consistency to enforce. At least, that's the way I've been thinking about it. If we think this is an area where it's desirable to have increased consistency between type checkers, we may want to clarify the desired behavior in the typing spec. |
Bug Report
Mypy raises false positive errors with anonymous and inline declaration of namedtuple types.
To Reproduce
This should be equivalent to the following, which mypy gets correct:
(Example taken from here: https://stackoverflow.com/a/26405216)
Expected Behavior
No error raised.
Actual Behavior
My Environment
The text was updated successfully, but these errors were encountered: