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
{{ message }}
Repository navigation
enum incorrectly narrowed to Never when instance check inside method #2299
fromenumimportEnum, autoclassFoo(Enum):
bar=auto()
baz=auto()
deffoo(self) ->None:
ifselfisFoo.bar:
reveal_type(self) # Type of "self" is "Never"deffoo(value: Foo) ->None:
ifvalueisFoo.bar:
reveal_type(value) # Type of "value" is "Literal[Foo.bar]"
VS Code extension or command-line
vscode, pylance v2021.9.1
Never is effectively the same as NoReturn, but NoReturn has a specific meaning in Python that would be confusing in this context since most people associate it with the return type of a function that never returns (hence the name). There has been discussion in the typing-sig of officially exporting a Never symbol from typing because it better reflects what happens when a type is narrowed to an empty union. The name Never is borrowed from TypeScript, where it appears as a built-in type.
Activity
DetachHead commentedon Sep 14, 2021
also why does pyright call it
Never? shouldn't it beNoReturn?erictraut commentedon Sep 14, 2021
Neveris effectively the same asNoReturn, butNoReturnhas a specific meaning in Python that would be confusing in this context since most people associate it with the return type of a function that never returns (hence the name). There has been discussion in the typing-sig of officially exporting aNeversymbol fromtypingbecause it better reflects what happens when a type is narrowed to an empty union. The nameNeveris borrowed from TypeScript, where it appears as a built-in type.erictraut commentedon Sep 14, 2021
I agree this is a bug in the
a is btype narrowing logic. Thanks for reporting it.erictraut commentedon Sep 14, 2021
This will be fixed in the next release.
erictraut commentedon Sep 16, 2021
This is included in pyright 1.1.169. It will also be included in the next release of pylance.