Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Properly use proper subtyping for callables#16343
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Diff frommypy_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) -> Anydiscord.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] |
JukkaL left a comment
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 fromcomtypes before merging?
hauntsaninja left a comment
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
ilevkivskyi commentedOct 27, 2023
Yes, the new error in @hauntsaninja The |
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.