-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Allow adjacent conditionally-defined overloads #19042
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
base: master
Are you sure you want to change the base?
Allow adjacent conditionally-defined overloads #19042
Conversation
cc @cdce8p as original author - could you have a look, please? |
This comment has been minimized.
This comment has been minimized.
Okay, we've even had one such false positive in primer! https://github.com/enthought/comtypes/blob/430bbdca8c0a146139acb990146ecbe06bdbf803/comtypes/_post_coinit/misc.py#L143 |
This looks like it should fix #17521 as well, but I'm not able to check this right now. |
It does, thanks! I expected this to be too niche to run a mypy-issues scan, but that was a wrong estimate:( |
This comment has been minimized.
This comment has been minimized.
def spam(v: int) -> list[int]: ... | ||
|
||
def spam(v: "int | str") -> "list[str] | list[int]": | ||
return [] |
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.
Similar to above. Actually this looks identical to ham
. Was this intentional?
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.
Yes, it was (or rather didn't matter) as the only thing I was testing here was that two adjacent conditional overloads are interpreted correctly. But your other comment raises a good point, modified accordingly.
@@ -6310,6 +6310,31 @@ reveal_type(f12(A())) # N: Revealed type is "__main__.A" | |||
|
|||
[typing fixtures/typing-medium.pyi] | |||
|
|||
[case testAdjacentConditionalOverloads] | |||
# flags: --always-true True |
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 use some other name than True
, since this overlaps with the normal True
, which is confusing.
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.
Done, but I'm not sure it's actually better - all surrounding tests use --always-true True
, so now this one is inconsistent which might be surprising or misleading for future readers.
…9015-adjacent-conditional-overloads
Diff from mypy_primer, showing the effect of this PR on open source code: comtypes (https://github.com/enthought/comtypes)
- comtypes/_post_coinit/misc.py:146: error: An overloaded function outside a stub file must have an implementation [no-overload-impl]
- comtypes/_post_coinit/misc.py:162: error: Name "CoGetClassObject" already defined on line 146 [no-redef]
|
Fixes #19015. Fixes #17521. Side question: why do we do that extra work to show "is already defined" error instead of "implementation must come last" in the following setting?
We have to track it specially and it doesn't work when
f2
is decorated, and I struggle to understand how "already defined" is better than an overload-specific message "implementation must come last".