Skip to content

Commit 43e130b

Browse files
authored
Update CHANGELOG.md to point out PEP 695 initial support (#17164)
1 parent 400eece commit 43e130b

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

CHANGELOG.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,42 @@ can be used with earlier Python releases by importing `TypeVar` from
6666
This feature was contributed by Marc Mueller (PR [16878](https://github.com/python/mypy/pull/16878)
6767
and PR [16925](https://github.com/python/mypy/pull/16925)).
6868

69+
#### Support TypeAliasType (PEP 695)
70+
As part of the initial steps towards implementing [PEP 695](https://peps.python.org/pep-0695/), mypy now supports `TypeAliasType`.
71+
`TypeAliasType` provides a backport of the new `type` statement in Python 3.12.
72+
73+
```python
74+
type ListOrSet[T] = list[T] | set[T]
75+
```
76+
77+
is equivalent to:
78+
79+
```python
80+
T = TypeVar("T")
81+
ListOrSet = TypeAliasType("ListOrSet", list[T] | set[T], type_params=(T,))
82+
```
83+
84+
Example of use in mypy:
85+
86+
```python
87+
from typing_extensions import TypeAliasType, TypeVar
88+
89+
NewUnionType = TypeAliasType("NewUnionType", int | str)
90+
x: NewUnionType = 42
91+
y: NewUnionType = 'a'
92+
z: NewUnionType = object() # error: Incompatible types in assignment (expression has type "object", variable has type "int | str") [assignment]
93+
94+
T = TypeVar("T")
95+
ListOrSet = TypeAliasType("ListOrSet", list[T] | set[T], type_params=(T,))
96+
a: ListOrSet[int] = [1, 2]
97+
b: ListOrSet[str] = {'a', 'b'}
98+
c: ListOrSet[str] = 'test' # error: Incompatible types in assignment (expression has type "str", variable has type "list[str] | set[str]") [assignment]
99+
```
100+
101+
`TypeAliasType` was added to the `typing` module in Python 3.12, but it can be used with earlier Python releases by importing from `typing_extensions`.
102+
103+
This feature was contributed by Ali Hamdan (PR [16926](https://github.com/python/mypy/pull/16926), PR [17038](https://github.com/python/mypy/pull/17038) and PR [17053](https://github.com/python/mypy/pull/17053))
104+
69105
#### Detect Additional Unsafe Uses of super()
70106

71107
Mypy will reject unsafe uses of `super()` more consistently, when the target has a
@@ -98,15 +134,13 @@ This feature was contributed by Shantanu (PR [16756](https://github.com/python/m
98134
- Optimize TYPE_CHECKING to False at Runtime (Srinivas Lade, PR [16263](https://github.com/python/mypy/pull/16263))
99135
- Fix compilation of unreachable comprehensions (Richard Si, PR [15721](https://github.com/python/mypy/pull/15721))
100136
- Don't crash on non-inlinable final local reads (Richard Si, PR [15719](https://github.com/python/mypy/pull/15719))
101-
- Support `TypeAliasType` (Ali Hamdan, PR [16926](https://github.com/python/mypy/pull/16926))
102137

103138
#### Documentation Improvements
104139
- Import `TypedDict` from `typing` instead of `typing_extensions` (Riccardo Di Maio, PR [16958](https://github.com/python/mypy/pull/16958))
105140
- Add missing `mutable-override` to section title (James Braza, PR [16886](https://github.com/python/mypy/pull/16886))
106141

107142
#### Error Reporting Improvements
108143

109-
- Improve error message for bound TypeVar in TypeAliasType (Ali Hamdan, PR [17053](https://github.com/python/mypy/pull/17053))
110144
- Use lower-case generics more consistently in error messages (Jukka Lehtosalo, PR [17035](https://github.com/python/mypy/pull/17035))
111145

112146
#### Other Notable Changes and Fixes
@@ -116,7 +150,6 @@ This feature was contributed by Shantanu (PR [16756](https://github.com/python/m
116150
- Narrow individual items when matching a tuple to a sequence pattern (Loïc Simon, PR [16905](https://github.com/python/mypy/pull/16905))
117151
- Fix false positive from type variable within TypeGuard or TypeIs (Evgeniy Slobodkin, PR [17071](https://github.com/python/mypy/pull/17071))
118152
- Improve `yield from` inference for unions of generators (Shantanu, PR [16717](https://github.com/python/mypy/pull/16717))
119-
- Support `TypeAliasType` in a class scope (Ali Hamdan, PR [17038](https://github.com/python/mypy/pull/17038))
120153
- Fix emulating hash method logic in `attrs` classes (Hashem, PR [17016](https://github.com/python/mypy/pull/17016))
121154
- Add reverted typeshed commit that uses `ParamSpec` for `functools.wraps` (Tamir Duberstein, PR [16942](https://github.com/python/mypy/pull/16942))
122155
- Fix type narrowing for `types.EllipsisType` (Shantanu, PR [17003](https://github.com/python/mypy/pull/17003))

0 commit comments

Comments
 (0)