You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a function has two overloads, one taking Literal[True] and the other Literal[False], pyright throws an error when trying to call it with a bool value or even with a Literal[True, False] value.
Changing bool in the implementation of f1 below to Literal[True, False] does not change the behavior. Using non-bool literals does not produce the issue.
Code or Screenshots
fromtypingimportLiteral, overload@overloaddeff1(c: Literal[False] = ...) ->str: ...
@overloaddeff1(c: Literal[True] = ...) ->int: ...
deff1(c: bool=False) ->str|int: ...
defr_bool() ->bool: ...
defr_literal() ->Literal[True, False]: ...
f1(r_bool()) # no overload matches for f1f1(r_literal()) # no overload matches for f1
VS Code extension or command-line
Both, pyright CLI is 1.1.367
I do not remember seeing that problem before so maybe it is a recent update.
The text was updated successfully, but these errors were encountered:
Pyright doesn't expand bool into Literal[True, False] in this case. That's an intentional decision, as expansion of this sort would be computationally expensive in a hot path within the type analyzer.
Which I understand, but if you do not expand bool into Literal[True, False], why collapse Literal[True, False] into bool (in the above exxample r_literal() is deduced to return bool)?
Describe the bug
When a function has two overloads, one taking
Literal[True]
and the otherLiteral[False]
, pyright throws an error when trying to call it with abool
value or even with aLiteral[True, False]
value.Changing
bool
in the implementation off1
below toLiteral[True, False]
does not change the behavior. Using non-bool literals does not produce the issue.Code or Screenshots
VS Code extension or command-line
Both, pyright CLI is 1.1.367
I do not remember seeing that problem before so maybe it is a recent update.
The text was updated successfully, but these errors were encountered: