-
-
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
Fixes type narrowing for overlaping runtime types #11273
Conversation
This comment has been minimized.
This comment has been minimized.
I am not sure what to do with this one. Maybe I should create a PR for
Looks like we fixed a typing bug here 🎉 from typing import Optional, Callable, Awaitable
async def some(x: Optional[Callable[[], Awaitable[str]]]) -> str:
if x is not None:
response = x()
if isinstance(response, Awaitable):
reveal_type(response) # N: Revealed type is "typing.Awaitable[builtins.str]"
return await response
else:
reveal_type(response) # N: Revealed type is "<nothing>"
return response
Cannot reproduce this one for now 🤔 |
Diff from mypy_primer, showing the effect of this PR on open source code: pydantic (https://github.com/samuelcolvin/pydantic.git)
+ pydantic/utils.py:554: error: <nothing> has no attribute "__class__" [attr-defined]
pandas (https://github.com/pandas-dev/pandas.git)
+ pandas/core/indexers/utils.py:360: error: <nothing> has no attribute "stop" [attr-defined]
+ pandas/core/indexers/utils.py:360: error: <nothing> has no attribute "start" [attr-defined]
+ pandas/core/indexers/utils.py:360: error: <nothing> has no attribute "step" [attr-defined]
+ pandas/core/common.py:131: error: <nothing> has no attribute "dtype" [attr-defined]
websockets (https://github.com/aaugustin/websockets.git)
+ src/websockets/legacy/server.py:364: error: unused "type: ignore" comment
+ src/websockets/legacy/server.py:592: error: unused "type: ignore" 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.
Thanks for the fix!
Closes #11913 Refs #11273 Co-authored-by: Shantanu <[email protected]>
Closes #11913 Refs #11273 Co-authored-by: Shantanu <[email protected]>
Closes python#11913 Refs python#11273 Co-authored-by: Shantanu <[email protected]>
As always, fixing issues with type narrowing / inference is always very hard, because small changes can backfire.
But, this looks as a simple change. Let's see how tests will behave.
Closes #11272