-
-
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
Properly use proper subtyping for callables #16343
Conversation
Diff from mypy_primer, showing the effect of this PR on open source code: porcupine (https://github.com/Akuli/porcupine): typechecking got 1.41x slower (30.7s -> 43.3s)
(Performance measurements are based on a single noisy sample)
comtypes (https://github.com/enthought/comtypes)
+ comtypes/client/_events.py:116: error: All conditional function variants must have identical signatures [misc]
+ comtypes/client/_events.py:116: note: Original:
+ comtypes/client/_events.py:116: note: def error_printer(self: Any, this: Any, *args: Any, **kw: Any) -> Any
+ comtypes/client/_events.py:116: note: Redefinition:
+ comtypes/client/_events.py:116: note: def error_printer(*args: Any, **kw: Any) -> Any
discord.py (https://github.com/Rapptz/discord.py)
- discord/app_commands/commands.py:2381: error: Item "function" of "Callable[[Any, Interaction[Any], VarArg(Any), KwArg(Any)], Coroutine[Any, Any, Any]] | Callable[[Interaction[Any], VarArg(Any), KwArg(Any)], Coroutine[Any, Any, Any]]" has no attribute "__discord_app_commands_checks__" [union-attr]
+ discord/app_commands/commands.py:2381: error: Item "function" of "Callable[[Any, Interaction[Any], VarArg(Any), KwArg(Any)], Coroutine[Any, Any, Any]] | Callable[[Interaction[Any], VarArg(Any), KwArg(Any)], Coroutine[Any, Any, Any]] | Callable[[Interaction[Any], Member], Coroutine[Any, Any, Any]] | Callable[[Interaction[Any], User], Coroutine[Any, Any, Any]] | Callable[[Interaction[Any], Message], Coroutine[Any, Any, Any]]" has no attribute "__discord_app_commands_checks__" [union-attr]
- discord/app_commands/commands.py:2383: error: Item "function" of "Callable[[Any, Interaction[Any], VarArg(Any), KwArg(Any)], Coroutine[Any, Any, Any]] | Callable[[Interaction[Any], VarArg(Any), KwArg(Any)], Coroutine[Any, Any, Any]]" has no attribute "__discord_app_commands_checks__" [union-attr]
+ discord/app_commands/commands.py:2383: error: Item "function" of "Callable[[Any, Interaction[Any], VarArg(Any), KwArg(Any)], Coroutine[Any, Any, Any]] | Callable[[Interaction[Any], VarArg(Any), KwArg(Any)], Coroutine[Any, Any, Any]] | Callable[[Interaction[Any], Member], Coroutine[Any, Any, Any]] | Callable[[Interaction[Any], User], Coroutine[Any, Any, Any]] | Callable[[Interaction[Any], Message], Coroutine[Any, Any, Any]]" has no attribute "__discord_app_commands_checks__" [union-attr]
|
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.
Again, thanks for the quick fix! It's interesting that this wasn't noticed earlier.
The impact doesn't look huge based on mypy_primer, though can you have a look at the output from comtypes
before merging?
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.
comtypes primer hit looks correct, reveal_type(func(spam))
in the test changing seems a little unfortunate
Yes, the new error in @hauntsaninja The |
This reverts commit 5c6ca5c.
Fixes #16338
This is kind of a major change, but it is technically correct: we should not treat
(*args: Any, **kwargs: Any)
special inis_proper_subtype()
(only inis_subtype()
). Unfortunately, this requires an additional flag foris_callable_compatible()
, since currently we are passing the subtype kind information via a callback, which is not applicable to handling argument kinds.