From ce4f0c13c8aa9a9533df03771021413cc9901042 Mon Sep 17 00:00:00 2001 From: Sachaa-Thanasius Date: Thu, 3 Oct 2024 17:05:54 +0530 Subject: [PATCH] "Fix" some typing shims for 3.10+. --- src/defer_imports/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/defer_imports/__init__.py b/src/defer_imports/__init__.py index ad72e9b..1497278 100644 --- a/src/defer_imports/__init__.py +++ b/src/defer_imports/__init__.py @@ -134,8 +134,11 @@ def _final(f: object) -> object: if sys.version_info >= (3, 10): # pragma: >=3.10 cover - _TypeAlias: typing.TypeAlias = "typing.TypeAlias" - _TypeGuard: typing.TypeAlias = "typing.TypeGuard" + if TYPE_CHECKING: + from typing import TypeAlias as _TypeAlias, TypeGuard as _TypeGuard + else: + _TypeAlias: typing.TypeAlias = "typing.TypeAlias" + _TypeGuard: typing.TypeAlias = "typing.TypeGuard" elif TYPE_CHECKING: from typing_extensions import TypeAlias as _TypeAlias, TypeGuard as _TypeGuard else: # pragma: <3.10 cover @@ -157,7 +160,10 @@ class _TypeGuard(metaclass=_PlaceholderMeta): if sys.version_info >= (3, 11): # pragma: >=3.11 cover - _Self: _TypeAlias = "typing.Self" + if TYPE_CHECKING: + from typing import Self as _Self + else: + _Self: _TypeAlias = "typing.Self" elif TYPE_CHECKING: from typing_extensions import Self as _Self else: # pragma: <3.11 cover