From e6769b2e5683d240e68666e6e7f95afe83fd8ef3 Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Tue, 30 Apr 2024 17:07:51 +0300 Subject: [PATCH 1/3] Use typing_extensions only when needed Annotated was added in Python 3.9 Literal was added in Python 3.8 --- inflect/__init__.py | 7 ++++++- pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/inflect/__init__.py b/inflect/__init__.py index d0eded1..361f46e 100644 --- a/inflect/__init__.py +++ b/inflect/__init__.py @@ -68,6 +68,7 @@ Dict, Iterable, List, + Literal, Match, Optional, Sequence, @@ -78,7 +79,11 @@ from more_itertools import windowed_complete from typeguard import typechecked -from typing_extensions import Annotated, Literal +try: + # Python 3.9+ + from typing import Annotated +except ImportError: + from typing_extensions import Annotated class UnknownClassicalModeError(Exception): diff --git a/pyproject.toml b/pyproject.toml index 1cb9e5e..cb5a0a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ requires-python = ">=3.8" dependencies = [ "more_itertools", "typeguard >= 4.0.1", - "typing_extensions", + "typing_extensions ; python_version<'3.9'", ] keywords = [ "plural", From 7d1571bd08f38a88a06a02af786ece816e858442 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 20 Jun 2024 14:07:28 -0400 Subject: [PATCH 2/3] Move compatibility logic into its own module. --- inflect/__init__.py | 7 ++----- inflect/compat/__init__.py | 0 inflect/compat/py38.py | 7 +++++++ 3 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 inflect/compat/__init__.py create mode 100644 inflect/compat/py38.py diff --git a/inflect/__init__.py b/inflect/__init__.py index 361f46e..3eec27f 100644 --- a/inflect/__init__.py +++ b/inflect/__init__.py @@ -79,11 +79,8 @@ from more_itertools import windowed_complete from typeguard import typechecked -try: - # Python 3.9+ - from typing import Annotated -except ImportError: - from typing_extensions import Annotated + +from .compat.py38 import Annotated class UnknownClassicalModeError(Exception): diff --git a/inflect/compat/__init__.py b/inflect/compat/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/inflect/compat/py38.py b/inflect/compat/py38.py new file mode 100644 index 0000000..a2d01bd --- /dev/null +++ b/inflect/compat/py38.py @@ -0,0 +1,7 @@ +import sys + + +if sys.version_info > (3, 9): + from typing import Annotated +else: # pragma: no cover + from typing_extensions import Annotated # noqa: F401 From c6538dc37c841151a51dbb15b4e423828c93c498 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 20 Jun 2024 14:08:28 -0400 Subject: [PATCH 3/3] Add news fragment. --- newsfragments/211.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/211.feature.rst diff --git a/newsfragments/211.feature.rst b/newsfragments/211.feature.rst new file mode 100644 index 0000000..3971e55 --- /dev/null +++ b/newsfragments/211.feature.rst @@ -0,0 +1 @@ +Restricted typing_extensions to Python 3.8. \ No newline at end of file