From 2c39991ace6814dd09f829f989076fc804da00ea Mon Sep 17 00:00:00 2001 From: Jordan Cook Date: Fri, 17 Nov 2023 13:08:45 -0600 Subject: [PATCH 1/2] Import typing_extensions.TypeAlias only on python < 3.11 --- HISTORY.md | 4 ++++ src/cattrs/_compat.py | 14 +++++++++++++- src/cattrs/dispatch.py | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 46cc0d03..23352fda 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,4 +1,8 @@ # History +## 23.2.1 (UNRELEASED) + +- Fix unnecessary `typing_extensions` import on Python 3.11. + ([#446](https://github.com/python-attrs/cattrs/issues/446)) ## 23.2.0 (2023-11-17) diff --git a/src/cattrs/_compat.py b/src/cattrs/_compat.py index 8cd437f3..428734d7 100644 --- a/src/cattrs/_compat.py +++ b/src/cattrs/_compat.py @@ -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 @@ -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""" diff --git a/src/cattrs/dispatch.py b/src/cattrs/dispatch.py index 74502b80..2aa525a8 100644 --- a/src/cattrs/dispatch.py +++ b/src/cattrs/dispatch.py @@ -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") From 92988037c25ffba1a76865dafebc3653d3ae4ea6 Mon Sep 17 00:00:00 2001 From: Tin Tvrtkovic Date: Fri, 17 Nov 2023 20:53:39 +0100 Subject: [PATCH 2/2] Tweak history --- HISTORY.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 23352fda..69f8a3c1 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,8 +1,9 @@ # History + ## 23.2.1 (UNRELEASED) - Fix unnecessary `typing_extensions` import on Python 3.11. - ([#446](https://github.com/python-attrs/cattrs/issues/446)) + ([#446](https://github.com/python-attrs/cattrs/issues/446) [#447](https://github.com/python-attrs/cattrs/pull/447)) ## 23.2.0 (2023-11-17)