Bug Report
Type narrowing can't remove type(None) from a union.
To Reproduce
def get_class(x: int) -> type[str | None]: if x > 0: return str else: return type(None) x = get_class(1) if x is type(None): print("hi") else: x("test") # Cannot instantiate type "Type[None]"
Expected Behavior
Type narrowing should eliminate that possibility. It works with None, but not NoneType.
Actual Behavior
Cannot instantiate type "Type[None]"
Your Environment
mypy 1.16.0 Python 3.12.10
Activity