Fixes type narrowing for overlaping runtime types#11273
Merged
hauntsaninja merged 3 commits intopython:masterfrom Oct 31, 2021
sobolevn:issue-11272
Merged
Fixes type narrowing for overlaping runtime types#11273hauntsaninja merged 3 commits intopython:masterfrom sobolevn:issue-11272
hauntsaninja merged 3 commits intopython:masterfrom
sobolevn:issue-11272
Conversation
This comment has been minimized.
This comment has been minimized.
Member
Author
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 🤔 |
Contributor
|
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
|
This was referenced Oct 5, 2021
hauntsaninja
approved these changes
Oct 10, 2021
Collaborator
hauntsaninja
left a comment
There was a problem hiding this comment.
Thanks for the fix!
13 tasks
tushar-deepsource
pushed a commit
to DeepSourceCorp/mypy
that referenced
this pull request
Jan 20, 2022
tushar-deepsource
pushed a commit
to DeepSourceCorp/mypy
that referenced
this pull request
Jan 20, 2022
Closes python#11913 Refs python#11273 Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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