Pyright fails to resolve `type(None)` to the `None` singleton, preventing standard type narrowing
bug
### 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
```python
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
4 条评论