Skip to content
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

[spec] Overload processing order #1803

Open
srittau opened this issue Jul 15, 2024 · 2 comments
Open

[spec] Overload processing order #1803

srittau opened this issue Jul 15, 2024 · 2 comments
Labels
topic: typing spec For improving the typing spec

Comments

@srittau
Copy link
Collaborator

srittau commented Jul 15, 2024

It's my understanding that overloads are processed in order. I.e. given the following overloads:

@overload
def foo(x: int) -> None: ...
@overload
def foo(x: int | str) -> None: ...
@overload
def foo(x: str) -> None: ...

When called with an int, the first overload is matched, when called with a str, the second is matched. The third is never matched. (Not going into what happens when called with int | str.) Currently, this behavior is not mentioned in the spec.

@srittau srittau added the topic: typing spec For improving the typing spec label Jul 15, 2024
@srittau
Copy link
Collaborator Author

srittau commented Jul 15, 2024

Also, overload "merging" behavior plays into this a little. E.g. given the example above and assuming that only the first and last overload were specified, could foo be called with int | str. I think the answer is "no". The call must match one of the overloads exactly and only that signature is looked at. But I'm not sure whether there aren't type checkers that are smarter.

@JelleZijlstra
Copy link
Member

Overloads are generally virtually unspecified, and the behavior of different type checkers doesn't match that well. I know this is on Eric's list of potential areas to cover, but it will be hard to specify the behavior precisely as there is a lot of complexity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: typing spec For improving the typing spec
Projects
None yet
Development

No branches or pull requests

2 participants