-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Remove and refactor old overload selection logic #5321
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
Merged
ilevkivskyi
merged 4 commits into
python:master
from
Michael0x2a:remove-old-overload-selection-algo
Aug 27, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1223,11 +1223,8 @@ class D: | |
def __get__(self, inst: Base, own: Type[Base]) -> str: pass | ||
[builtins fixtures/bool.pyi] | ||
[out] | ||
main:5: error: Revealed type is 'Any' | ||
main:5: error: No overload variant of "__get__" of "D" matches argument types "None", "Type[A]" | ||
main:5: note: Possible overload variants: | ||
main:5: note: def __get__(self, inst: None, own: Type[Base]) -> D | ||
main:5: note: def __get__(self, inst: Base, own: Type[Base]) -> str | ||
main:5: error: Revealed type is 'd.D' | ||
main:5: error: Argument 2 to "__get__" of "D" has incompatible type "Type[A]"; expected "Type[Base]" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't we have the same nicer error for the case right below? (This is very low priority.) |
||
main:6: error: Revealed type is 'Any' | ||
main:6: error: No overload variant of "__get__" of "D" matches argument types "A", "Type[A]" | ||
main:6: note: Possible overload variants: | ||
|
@@ -3016,16 +3013,10 @@ def f(a: Type[B]) -> None: pass | |
@overload | ||
def f(a: int) -> None: pass | ||
|
||
f(A) # E: No overload variant of "f" matches argument type "Type[A]" \ | ||
# N: Possible overload variants: \ | ||
# N: def f(a: Type[B]) -> None \ | ||
# N: def f(a: int) -> None | ||
f(A) # E: Argument 1 to "f" has incompatible type "Type[A]"; expected "Type[B]" | ||
f(B) | ||
f(C) | ||
f(AType) # E: No overload variant of "f" matches argument type "Type[A]" \ | ||
# N: Possible overload variants: \ | ||
# N: def f(a: Type[B]) -> None \ | ||
# N: def f(a: int) -> None | ||
f(AType) # E: Argument 1 to "f" has incompatible type "Type[A]"; expected "Type[B]" | ||
f(BType) | ||
f(CType) | ||
[builtins fixtures/classmethod.pyi] | ||
|
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
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.
I am not sure this is a good idea to have
d.D
instead ofAny
. In case of errors we typically returnAny
to avoid other (potentially bogus) errors.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.
I think in this case, what's happening is that there's actually only one plausible matching overload -- when we do
A.f
andf
is a descriptor, we always end up calling the overloaddef __get__(self, inst: None, own: Type[Base]) -> D
.So, since only one variant is a plausible match, we just infer that variant's return type. (And regarding your comment below -- this is also why we don't bother showing the possible overload variants here).
I think this behavior is consistent with how we handle bad calls to regular functions. E.g. mypy will infer the return type instead of Any in this program:
Granted, I don't think it's obvious that only one variant will be selected here, so I added another test case for this behavior.
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.