-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Changes from 2 commits
6817b4a
85f7385
b53a445
4dcf96c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| from typing import overload | ||
|
|
||
| if True: | ||
| @overload | ||
| def ham(v: str) -> list[str]: ... | ||
|
|
||
| @overload | ||
| def ham(v: int) -> list[int]: ... | ||
|
|
||
| def ham(v: "int | str") -> "list[str] | list[int]": | ||
| return [] | ||
sterliakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if True: | ||
| @overload | ||
| def spam(v: str) -> list[str]: ... | ||
|
|
||
| @overload | ||
| def spam(v: int) -> list[int]: ... | ||
|
|
||
| def spam(v: "int | str") -> "list[str] | list[int]": | ||
| return [] | ||
|
||
|
|
||
|
|
||
| [case testOverloadIfUnconditionalFuncDef] | ||
| # flags: --always-true True --always-false False | ||
| from typing import overload | ||
|
|
||
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 normalTrue, 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.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.
Ah I didn't notice the others. This may be still useful in case future readers use the new approach as an example.