-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Use class name as namespace for type variables #12590
Conversation
Diff from mypy_primer, showing the effect of this PR on open source code: websockets (https://github.com/aaugustin/websockets)
+ src/websockets/legacy/protocol.py:687: error: Argument 1 to "__anext__" of "AsyncIterator" has incompatible type "AsyncIterator[_T_co]"; expected "AsyncIterator[_T_co]"
xarray (https://github.com/pydata/xarray)
- xarray/core/alignment.py:534: error: Argument 1 to "_reindex_one" of "Aligner" has incompatible type "Tuple[DataAlignable, Dict[Tuple[Tuple[Tuple[Hashable, Tuple[Hashable, ...]], ...], Type[Index]], Index]]"; expected "DataAlignable" [arg-type]
Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/abc.py:2860: error: Signature of "copy" incompatible with supertype "ExecutableCommand" [override]
- tanjun/abc.py:2860: note: Superclass:
- tanjun/abc.py:2860: note: def copy(self) -> MessageCommand[MessageContext]
- tanjun/abc.py:2860: note: Subclass:
- tanjun/abc.py:2860: note: def copy(self, *, parent: Optional[MessageCommandGroup[Any]] = ...) -> MessageCommand[_CommandCallbackSigT]
- tanjun/commands/slash.py:1272: error: Return type "SlashCommand[_CommandCallbackSigT]" of "bind_client" incompatible with return type "SlashCommand[SlashContext]" in supertype "PartialCommand" [override]
- tanjun/commands/slash.py:1272: error: Return type "SlashCommand[_CommandCallbackSigT]" of "bind_client" incompatible with return type "SlashCommand[SlashContext]" in supertype "ExecutableCommand" [override]
- tanjun/commands/slash.py:2454: error: Signature of "copy" incompatible with supertype "PartialCommand" [override]
- tanjun/commands/slash.py:2454: note: Superclass:
- tanjun/commands/slash.py:2454: note: def copy(self, *, _new: bool = ...) -> SlashCommand[SlashContext]
- tanjun/commands/slash.py:2454: note: Subclass:
- tanjun/commands/slash.py:2454: note: def copy(self, *, _new: bool = ..., parent: Optional[SlashCommandGroup] = ...) -> SlashCommand[_CommandCallbackSigT]
- tanjun/commands/slash.py:2454: error: Signature of "copy" incompatible with supertype "ExecutableCommand" [override]
- tanjun/commands/slash.py:2454: note: def copy(self) -> SlashCommand[SlashContext]
- tanjun/commands/slash.py:2454: note: def copy(self, *, _new: bool = ..., parent: Optional[SlashCommandGroup] = ...) -> SlashCommand[_CommandCallbackSigT]
- tanjun/commands/message.py:249: error: Return type "MessageCommand[_CommandCallbackSigT]" of "bind_client" incompatible with return type "MessageCommand[MessageContext]" in supertype "PartialCommand" [override]
- tanjun/commands/message.py:249: error: Return type "MessageCommand[_CommandCallbackSigT]" of "bind_client" incompatible with return type "MessageCommand[MessageContext]" in supertype "ExecutableCommand" [override]
- tanjun/commands/message.py:257: error: Return type "MessageCommand[_CommandCallbackSigT]" of "bind_component" incompatible with return type "MessageCommand[MessageContext]" in supertype "PartialCommand" [override]
- tanjun/commands/message.py:257: error: Return type "MessageCommand[_CommandCallbackSigT]" of "bind_component" incompatible with return type "MessageCommand[MessageContext]" in supertype "ExecutableCommand" [override]
- tanjun/commands/message.py:265: error: Signature of "copy" incompatible with supertype "PartialCommand" [override]
- tanjun/commands/message.py:265: note: Superclass:
- tanjun/commands/message.py:265: note: def copy(self, *, _new: bool = ...) -> MessageCommand[MessageContext]
- tanjun/commands/message.py:265: note: Subclass:
- tanjun/commands/message.py:265: note: def copy(self, *, parent: Optional[MessageCommandGroup[Any]] = ..., _new: bool = ...) -> MessageCommand[_CommandCallbackSigT]
- tanjun/commands/message.py:265: error: Signature of "copy" incompatible with supertype "ExecutableCommand" [override]
- tanjun/commands/message.py:265: note: def copy(self) -> MessageCommand[MessageContext]
- tanjun/commands/message.py:265: note: def copy(self, *, parent: Optional[MessageCommandGroup[Any]] = ..., _new: bool = ...) -> MessageCommand[_CommandCallbackSigT]
- tanjun/commands/message.py:423: error: Signature of "copy" incompatible with supertype "PartialCommand" [override]
- tanjun/commands/message.py:423: note: Superclass:
- tanjun/commands/message.py:423: note: def copy(self, *, _new: bool = ...) -> MessageCommandGroup[MessageContext]
- tanjun/commands/message.py:423: note: Subclass:
- tanjun/commands/message.py:423: note: def copy(self, *, parent: Optional[MessageCommandGroup[Any]] = ..., _new: bool = ...) -> MessageCommandGroup[_CommandCallbackSigT]
- tanjun/commands/message.py:423: error: Signature of "copy" incompatible with supertype "ExecutableCommand" [override]
- tanjun/commands/message.py:423: note: def copy(self) -> MessageCommandGroup[MessageContext]
- tanjun/commands/message.py:423: note: def copy(self, *, parent: Optional[MessageCommandGroup[Any]] = ..., _new: bool = ...) -> MessageCommandGroup[_CommandCallbackSigT]
- tanjun/commands/message.py:493: error: Return type "MessageCommandGroup[_CommandCallbackSigT]" of "bind_client" incompatible with return type "MessageCommandGroup[MessageContext]" in supertype "PartialCommand" [override]
- tanjun/commands/message.py:493: error: Return type "MessageCommandGroup[_CommandCallbackSigT]" of "bind_client" incompatible with return type "MessageCommandGroup[MessageContext]" in supertype "ExecutableCommand" [override]
- tanjun/commands/message.py:501: error: Return type "MessageCommandGroup[_CommandCallbackSigT]" of "bind_component" incompatible with return type "MessageCommandGroup[MessageContext]" in supertype "PartialCommand" [override]
- tanjun/commands/message.py:501: error: Return type "MessageCommandGroup[_CommandCallbackSigT]" of "bind_component" incompatible with return type "MessageCommandGroup[MessageContext]" in supertype "ExecutableCommand" [override]
- tanjun/commands/menu.py:448: error: Return type "MenuCommand[_MenuCommandCallbackSigT, _MenuTypeT]" of "set_tracked_command" incompatible with return type "MenuCommand[MenuContext, _MenuTypeT]" in supertype "AppCommand" [override]
- tanjun/commands/menu.py:484: error: Signature of "copy" incompatible with supertype "PartialCommand" [override]
- tanjun/commands/menu.py:484: note: Superclass:
- tanjun/commands/menu.py:484: note: def copy(self, *, _new: bool = ...) -> MenuCommand[MenuContext, _MenuTypeT]
- tanjun/commands/menu.py:484: note: Subclass:
- tanjun/commands/menu.py:484: note: def copy(self, *, _new: bool = ..., parent: Optional[SlashCommandGroup] = ...) -> MenuCommand[_MenuCommandCallbackSigT, _MenuTypeT]
- tanjun/commands/menu.py:484: error: Signature of "copy" incompatible with supertype "ExecutableCommand" [override]
- tanjun/commands/menu.py:484: note: def copy(self) -> MenuCommand[MenuContext, _MenuTypeT]
- tanjun/commands/menu.py:484: note: def copy(self, *, _new: bool = ..., parent: Optional[SlashCommandGroup] = ...) -> MenuCommand[_MenuCommandCallbackSigT, _MenuTypeT]
|
The mypy-primer output looks suspicious, though I haven't investigated in detail. This error message won't be fun for anyone: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this namespacing is a better approach than my own PR (which essentially mutated the typevars on an existing class to be at least larger than every other in its inheritance tree). Should its test also be carried over, though?
It looks like websockets didn't have an error more or less accidentally before (one mypy bug hid another mypy bug). Mypy infers types with unbound type variables (which it shouldn't do), and previously two types with unbound type variables were considered compatible, whereas now there's an error. I'm going to try to improve the error message in a follow-up PR, however (or fix the leaking unbound type variables). @A5rocks I'll add the test case in a follow-up PR. |
This avoids confusion between type variables of two classes, which can happen at least in some edge cases. Type variables are only the same if both the numeric id and namespace match (plus meta level). Fixes #12588 (though the textual presentation of type variables doesn't take the namespace into consideration yet).
This reverts commit 20b0b9b.
This reverts commit 20b0b9b.
This reverts commit 20b0b9b.
This reverts commit 20b0b9b.
This avoids confusion between type variables of two classes, which can
happen at least in some edge cases. Type variables are only the same if
both the numeric id and namespace match (plus meta level).
Fixes #12588 (though the textual presentation of type variables doesn't
take the namespace into consideration yet).