Skip to content

Commit

Permalink
Import typing_extensions.TypeAlias only on python < 3.11 (#447)
Browse files Browse the repository at this point in the history
* Import typing_extensions.TypeAlias only on python < 3.11

* Tweak history

---------

Co-authored-by: Tin Tvrtkovic <tinchester@gmail.com>
  • Loading branch information
JWCook and Tinche committed Nov 17, 2023
1 parent 46be811 commit 25d15d6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# History

## 23.2.1 (UNRELEASED)

- Fix unnecessary `typing_extensions` import on Python 3.11.
([#446](https://github.com/python-attrs/cattrs/issues/446) [#447](https://github.com/python-attrs/cattrs/pull/447))

## 23.2.0 (2023-11-17)

- **Potentially breaking**: skip _attrs_ fields marked as `init=False` by default. This change is potentially breaking for unstructuring.
Expand Down
14 changes: 13 additions & 1 deletion src/cattrs/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
from attrs import fields as attrs_fields
from attrs import resolve_types

__all__ = ["ExceptionGroup", "ExtensionsTypedDict", "TypedDict", "is_typeddict"]
__all__ = [
"ExceptionGroup",
"ExtensionsTypedDict",
"TypedDict",
"TypeAlias",
"is_typeddict",
]

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

try:
from typing_extensions import TypeAlias
except ImportError:
assert sys.version_info >= (3, 11)
from typing import TypeAlias


def is_typeddict(cls):
"""Thin wrapper around typing(_extensions).is_typeddict"""
Expand Down
3 changes: 2 additions & 1 deletion src/cattrs/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from typing import Any, Callable, Dict, Generic, List, Optional, Tuple, TypeVar, Union

from attrs import Factory, define, field
from typing_extensions import TypeAlias

from cattrs._compat import TypeAlias

T = TypeVar("T")

Expand Down

0 comments on commit 25d15d6

Please sign in to comment.