-
Notifications
You must be signed in to change notification settings - Fork 768
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
Regression: Overloaded functions using Discriminated Unions with Boolean Literals now reports incompatible type #6420
Comments
This error is correct. The behavior you're seeing is due to a recent bug fix. Pyright (the type checker that underlies pylance) previously contained a bug that resulted in a false negative. It failed to report an overlapping overload in this case. With this bug now fixed, it correctly reports the issue. Until recently, there was no formal definition for an "overlapping overload" provided in the Python typing spec, but we've worked to address this omission. I wrote this new update to to the Python typing spec. Its contents have already gone through extensive review, and it's in its near-final form. Search for the "Overlapping Overloads" subsection if you're interested in the details. The problem with your code sample is that both overloads specify a default value for the third parameter ( Code sample in pyright playground from typing import Literal, overload
@overload
def foo(x: Literal[False] = False) -> int: ...
@overload
def foo(x: Literal[True] = True) -> str: ...
def foo(x: bool = False) -> int | str: ...
reveal_type(foo()) |
That's strange. Since the default value is |
If you would like to comment on the proposed spec update, here is the thread. |
This issue only starts appearing from Pylance 2024.9.1 and onwards. Works fine on 2024.8.2.
Environment data
Code Snippet
Expected behavior
No reports. This is a valid discriminated union.
Actual behavior
The text was updated successfully, but these errors were encountered: