-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
inspect
, asyncio
: Use more TypeGuard
s
#8057
Conversation
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
Interesting. @erictraut, any idea why the test cases I've added in this PR are failing pyright? Mypy seems to have no trouble with them. |
Mypy primer analysis Most of these are just noise: mypy is just emitting slightly different error messages for things that already failed to type check. + discord/ext/tasks/__init__.py:622: error: Incompatible return value type (got "Callable[..., CoroutineType[Any, Any, Any]]", expected "ET") This one looks like a true positive to me. Source code here: https://github.com/Rapptz/discord.py/blob/334ef1d7facce9dbfba2a6924bf57fc59bc827b5/discord/ext/tasks/__init__.py#L598-L622 aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/helpers.py:126: error: Incompatible redefinition (redefinition with type "Callable[[Any], bool]", original type overloaded function) [misc]
pyinstrument (https://github.com/joerick/pyinstrument)
+ pyinstrument/vendor/decorator.py:66: error: Incompatible redefinition (redefinition with type "Callable[[Any], Any]", original type overloaded function) These are both a little unfortunate, but can't really be helped. I think they will simply have to add |
@AlexWaygood, pyright doesn't currently support |
Thanks @erictraut!
I'm in no particular rush with this PR :)
If the performance impact is too large for pyright to tolerate, I suppose I could simply exclude the test cases from this PR -- these are the only bits that fail pyright. It seems that since pyright doesn't yet support combining I think it would be unfeasible to consider a version of this PR without the overloads, however: the results from mypy-primer indicate to me that merging a version of this PR without the overloads would lead to an unacceptable number of false-positive errors when type-checking. (Yet another option is obviously to close this PR and not bother too much about it.) |
This is included in pyright 1.1.255, which I just published. |
This comment has been minimized.
This comment has been minimized.
Thank you very much! Everything looks to be working well now; the tests I've added are passing CI nicely. For reviewers: mypy-primer analysis is in this comment here: #8057 (comment) |
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/tasks/__init__.py:564: error: Incompatible types in assignment (expression has type "FT", variable has type "None")
+ discord/ext/tasks/__init__.py:564: error: Incompatible types in assignment (expression has type "Callable[[VarArg(<nothing>), KwArg(<nothing>)], CoroutineType[Any, Any, <nothing>]]", variable has type "None")
+ discord/ext/tasks/__init__.py:565: error: Incompatible return value type (got "Callable[[VarArg(<nothing>), KwArg(<nothing>)], CoroutineType[Any, Any, <nothing>]]", expected "FT")
- discord/ext/tasks/__init__.py:592: error: Incompatible types in assignment (expression has type "FT", variable has type "None")
+ discord/ext/tasks/__init__.py:592: error: Incompatible types in assignment (expression has type "Callable[[VarArg(<nothing>), KwArg(<nothing>)], CoroutineType[Any, Any, <nothing>]]", variable has type "None")
+ discord/ext/tasks/__init__.py:593: error: Incompatible return value type (got "Callable[[VarArg(<nothing>), KwArg(<nothing>)], CoroutineType[Any, Any, <nothing>]]", expected "FT")
+ discord/ext/tasks/__init__.py:623: error: Incompatible return value type (got "Callable[..., CoroutineType[Any, Any, Any]]", expected "ET")
- discord/ext/commands/cog.py:215: error: Item "Group" of "Union[Any, Group, Command[Any, Any, Any]]" has no attribute "__cog_listener_names__"
+ discord/ext/commands/cog.py:215: error: "Callable[..., CoroutineType[Any, Any, Any]]" has no attribute "__cog_listener_names__"
- discord/ext/commands/cog.py:215: error: Item "Command[Any, Any, Any]" of "Union[Any, Group, Command[Any, Any, Any]]" has no attribute "__cog_listener_names__"
- discord/ext/commands/cog.py:218: error: Item "Group" of "Union[Any, Group, Command[Any, Any, Any]]" has no attribute "__name__"
- discord/ext/commands/cog.py:218: error: Item "Command[Any, Any, Any]" of "Union[Any, Group, Command[Any, Any, Any]]" has no attribute "__name__"
aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/helpers.py:126: error: Incompatible redefinition (redefinition with type "Callable[[Any], bool]", original type overloaded function) [misc]
pyinstrument (https://github.com/joerick/pyinstrument)
+ pyinstrument/vendor/decorator.py:66: error: Incompatible redefinition (redefinition with type "Callable[[Any], Any]", original type overloaded function)
|
Fixes #8009.