[ty] Allow values of type None in type expressions (#21263)

## Summary

Allow values of type `None` in type expressions. The [typing
spec](https://typing.python.org/en/latest/spec/annotations.html#type-and-annotation-expressions)
could be more explicit on whether this is actually allowed or not, but
it seems relatively harmless and does help in some use cases like:

```py
try:
    from module import MyClass
except ImportError:
    MyClass = None  # ty: ignore


def f(m: MyClass):
    pass
``` 

## Test Plan

Updated tests, ecosystem check.
This commit is contained in:
David Peter 2025-11-04 16:29:55 +01:00 committed by GitHub
parent d8106d38a0
commit 2e7ab00d51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 4 deletions

View file

@ -22,11 +22,8 @@ f(1)
```py
MyNone = None
# TODO: this should not be an error
# error: [invalid-type-form] "Variable of type `None` is not allowed in a type expression"
def g(x: MyNone):
# TODO: this should be `None`
reveal_type(x) # revealed: Unknown
reveal_type(x) # revealed: None
g(None)
```