diff --git a/class_singledispatch/__init__.py b/class_singledispatch/__init__.py index 7bb5fe4..6e2d748 100644 --- a/class_singledispatch/__init__.py +++ b/class_singledispatch/__init__.py @@ -11,10 +11,13 @@ from __future__ import annotations +import sys +from contextlib import suppress from functools import partial, singledispatch from typing import ( TYPE_CHECKING, Any, + ForwardRef, Generic, Type, TypeVar, @@ -29,22 +32,21 @@ from typing import overload -OldFashionGenericAlias = type(Type[object]) +OldFashionGenericAlias: type[object] = type(Type[object]) -try: - from types import GenericAlias # type: ignore # noqa: PGH003 -except ImportError: # pragma: no cover +if sys.version_info < (3, 9): GenericAlias = OldFashionGenericAlias +else: + from types import GenericAlias -try: # pragma: no cover - from typing_extensions import ParamSpec # type: ignore # noqa: PGH003 -except ImportError: # pragma: no cover - from typing import ParamSpec # type: ignore # noqa: PGH003 -try: - from eval_type_backport import ForwardRef # type: ignore # noqa: PGH003 -except ImportError: # pragma: no cover - from typing import ForwardRef # type: ignore # noqa: PGH003 +if sys.version_info < (3, 10): + from typing_extensions import ParamSpec +else: + from typing import ParamSpec + +with suppress(ImportError): + from eval_type_backport import ForwardRef # noqa: F811 __all__ = ( diff --git a/poetry.lock b/poetry.lock index 732000c..893c022 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1178,13 +1178,13 @@ test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest- [[package]] name = "pluggy" -version = "1.4.0" +version = "1.5.0" description = "plugin and hook calling mechanisms for python" optional = false python-versions = ">=3.8" files = [ - {file = "pluggy-1.4.0-py3-none-any.whl", hash = "sha256:7db9f7b503d67d1c5b95f59773ebb58a8c1c288129a88665838012cfb07b8981"}, - {file = "pluggy-1.4.0.tar.gz", hash = "sha256:8c85c2876142a764e5b7548e7d9a0e0ddb46f5185161049a79b7e974454223be"}, + {file = "pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669"}, + {file = "pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1"}, ] [package.extras] diff --git a/tests/test_class_singledispatch.py b/tests/test_class_singledispatch.py index 9a8ab9b..164c196 100644 --- a/tests/test_class_singledispatch.py +++ b/tests/test_class_singledispatch.py @@ -2,18 +2,16 @@ import enum import sys +from contextlib import suppress from dataclasses import dataclass -from typing import Type +from typing import ForwardRef, Type import pytest from class_singledispatch import class_singledispatch, resolve_annotated_type - -try: - from eval_type_backport import ForwardRef # type: ignore # noqa: PGH003 -except ImportError: - from typing import ForwardRef # type: ignore # noqa: PGH003 +with suppress(ImportError): + from eval_type_backport import ForwardRef @dataclass