Describe the bug
When type(None) is assigned to a variable and used in a Union type hint, Pyright fails to resolve it to the None singleton. This prevents standard type narrowing (e.g., if not obj.my_list) from removing the None branch, causing elements to be inferred as Unknown.
Code Sample
import typing
none_type = type(None) # Alias for the None singleton
class MyClass:
# Pyright treats this Union as list[str] | Unknown
my_list: typing.Union[list[str], none_type]
def fn(o: MyClass):
if not o.my_list:
return
# Expected: list[str]
# Actual: list[str | Unknown]
elements = [e for e in o.my_list]
Environment
Python 3.13, Pyright/Pylance v2026.2.1
Describe the bug
When
type(None)is assigned to a variable and used in aUniontype hint, Pyright fails to resolve it to theNonesingleton. This prevents standard type narrowing (e.g.,if not obj.my_list) from removing theNonebranch, causing elements to be inferred asUnknown.Code Sample
Environment
Python 3.13, Pyright/Pylance v2026.2.1