Skip to content

Commit 25d15d6

Browse files
JWCookTinche
andauthored
Import typing_extensions.TypeAlias only on python < 3.11 (#447)
* Import typing_extensions.TypeAlias only on python < 3.11 * Tweak history --------- Co-authored-by: Tin Tvrtkovic <[email protected]>
1 parent 46be811 commit 25d15d6

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# History
22

3+
## 23.2.1 (UNRELEASED)
4+
5+
- Fix unnecessary `typing_extensions` import on Python 3.11.
6+
([#446](https://github.com/python-attrs/cattrs/issues/446) [#447](https://github.com/python-attrs/cattrs/pull/447))
7+
38
## 23.2.0 (2023-11-17)
49

510
- **Potentially breaking**: skip _attrs_ fields marked as `init=False` by default. This change is potentially breaking for unstructuring.

src/cattrs/_compat.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
from attrs import fields as attrs_fields
2121
from attrs import resolve_types
2222

23-
__all__ = ["ExceptionGroup", "ExtensionsTypedDict", "TypedDict", "is_typeddict"]
23+
__all__ = [
24+
"ExceptionGroup",
25+
"ExtensionsTypedDict",
26+
"TypedDict",
27+
"TypeAlias",
28+
"is_typeddict",
29+
]
2430

2531
try:
2632
from typing_extensions import TypedDict as ExtensionsTypedDict
@@ -39,6 +45,12 @@
3945
assert sys.version_info >= (3, 10)
4046
from typing import is_typeddict as _is_typeddict
4147

48+
try:
49+
from typing_extensions import TypeAlias
50+
except ImportError:
51+
assert sys.version_info >= (3, 11)
52+
from typing import TypeAlias
53+
4254

4355
def is_typeddict(cls):
4456
"""Thin wrapper around typing(_extensions).is_typeddict"""

src/cattrs/dispatch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from typing import Any, Callable, Dict, Generic, List, Optional, Tuple, TypeVar, Union
33

44
from attrs import Factory, define, field
5-
from typing_extensions import TypeAlias
5+
6+
from cattrs._compat import TypeAlias
67

78
T = TypeVar("T")
89

0 commit comments

Comments
 (0)