-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Improve usage of outer context for inference #5699
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
decb5fd
Don't show errors before inference is done
a262692
Tweak tests
ilevkivskyi fb841b7
Remove some tests
ilevkivskyi d941c23
Update a comment in skipped test and remove now unneded fixture updates
ilevkivskyi e18a521
Add special case for optional return vs optional context
ilevkivskyi 517d7c2
Re-order special cases
ilevkivskyi fc603f4
Fix long line
ilevkivskyi 826806c
Updates on feedback; will add tests later
ilevkivskyi 17146f7
Add more tests
3441ed5
Merge branch 'outer-context' of https://github.com/ilevkivskyi/mypy i…
9a0af3c
Address CR
31d1ca2
Merge branch 'master' into outer-context
ilevkivskyi f3a28c2
Fix broken merge
ilevkivskyi 3cd7d25
Switch to invariant instances in special case
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
Maybe this is only reasonable if the generic instance type is invariant in some type arg? I wonder if that would be a bit more "principled".
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.
TBH I am not sure this is better. Currently, we ignore the return context for cases like
T <: int
but use it forT <: Iterable[int]
. So the only way how only usingT <: List[int]
will be better, is because invariant containers statistically have less subtypes. As I understand the original problem this solves is like this:In other words the problem appears when the return type appears as a variable in invariant context in one of argument types.
However, if you prefer to only use invariant ones, I can update this.
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.
What I meant is that if the context is, say,
List[object]
,List[int]
wouldn't be valid due to invariance, so we are more likely to want to use the surrounding type context and not rely on arguments only. However, if the context isIterable[object]
,Iterable[int]
would be okay, due co covariance, so we ignore the context. Whether there are many subtypes or not doesn't seem significant?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.
OK, this is actually exactly what I meant :-)
Iterable[object]
has more subtypes, such asIterable[int]
. WhileList[object]
doesn't have such, so it is typically better to still use it as a context. OK, I will modify the special case to reflect this.