Describe the bug
Pyright seems to handle NotImplementedType as a special case, and type narrowing and method resolving does not work correctly.
Code or Screenshots
from types import EllipsisType, NotImplementedType
def check1(val: int | str | NotImplementedType):
if isinstance(val, int):
print("Integer", val)
reveal_type(val) # pyright says: int | NotImplementedType
print("Does not type check (which is good)", val + 2) # But the report is incomplete
def check2(val: int | str | float):
if isinstance(val, int):
print("Integer", val)
reveal_type(val) # pyright says: int
def check3(val: int | str | EllipsisType):
if isinstance(val, int):
print("Integer", val)
reveal_type(val) # pyright says: int
def check4(val: int | NotImplementedType):
if isinstance(val, int):
print("Integer", val)
reveal_type(val) # pyright says: int | NotImplementedType
print("Type checks (but should not)", val + 2)
VS Code extension or command-line
I ran the command line version of Pyright, version 1.5.0, with: npx pyright@latest not_implemented_test.py
The output is:
/tmp/not_implemented_test.py
/tmp/not_implemented_test.py:7:21 - information: Type of "val" is "int | NotImplementedType"
/tmp/not_implemented_test.py:8:22 - error: Operator "+" not supported for types "int | NotImplementedType | str" and "Literal[2]"
Operator "+" not supported for types "str" and "Literal[2]" when expected type is "object" (reportOperatorIssue)
/tmp/not_implemented_test.py:14:21 - information: Type of "val" is "int"
/tmp/not_implemented_test.py:20:21 - information: Type of "val" is "int"
/tmp/not_implemented_test.py:26:21 - information: Type of "val" is "int | NotImplementedType"
1 error, 0 warnings, 4 informations
Describe the bug
Pyright seems to handle
NotImplementedTypeas a special case, and type narrowing and method resolving does not work correctly.Code or Screenshots
VS Code extension or command-line
I ran the command line version of Pyright, version 1.5.0, with:
npx pyright@latest not_implemented_test.pyThe output is: