Commit 30a2007
authored
Preserve typevar default None in type alias (python#18197)
Fixes python#18188
Currently it seems that `None` is dropped from type variable defaults
when assigning generic class to a type alias.
<details>
<summary>Example</summary>
```python
from typing_extensions import TypeVar
from typing import Generic, Union
T1 = TypeVar("T1", default=Union[int, None])
T2 = TypeVar("T2", default=Union[int, None])
class A(Generic[T1, T2]):
def __init__(self, a: T1, b: T2) -> None:
self.a = a
self.b = b
MyA = A[T1, int]
a: MyA = A(None, 10) # error: Argument 1 to "A" has incompatible type "None"; expected "int" [arg-type]
reveal_type(a.a)
```
</details>
The change is similar to python#168591 parent 499adae commit 30a2007
2 files changed
+23
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2277 | 2277 | | |
2278 | 2278 | | |
2279 | 2279 | | |
2280 | | - | |
| 2280 | + | |
| 2281 | + | |
2281 | 2282 | | |
2282 | 2283 | | |
2283 | 2284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
728 | 728 | | |
729 | 729 | | |
730 | 730 | | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
0 commit comments