Skip to content

Commit 004e49f

Browse files
committed
Add news entry
1 parent 56c53b9 commit 004e49f

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

class_singledispatch/__init__.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212
from __future__ import annotations
1313

14+
import sys
15+
from contextlib import suppress
1416
from functools import partial, singledispatch
1517
from typing import (
1618
TYPE_CHECKING,
1719
Any,
20+
ForwardRef,
1821
Generic,
1922
Type,
2023
TypeVar,
@@ -29,22 +32,21 @@
2932
from typing import overload
3033

3134

32-
OldFashionGenericAlias = type(Type[object])
35+
OldFashionGenericAlias: type[object] = type(Type[object])
3336

34-
try:
35-
from types import GenericAlias # type: ignore # noqa: PGH003
36-
except ImportError: # pragma: no cover
37+
if sys.version_info < (3, 9):
3738
GenericAlias = OldFashionGenericAlias
39+
else:
40+
from types import GenericAlias
3841

39-
try: # pragma: no cover
40-
from typing_extensions import ParamSpec # type: ignore # noqa: PGH003
41-
except ImportError: # pragma: no cover
42-
from typing import ParamSpec # type: ignore # noqa: PGH003
4342

44-
try:
45-
from eval_type_backport import ForwardRef # type: ignore # noqa: PGH003
46-
except ImportError: # pragma: no cover
47-
from typing import ForwardRef # type: ignore # noqa: PGH003
43+
if sys.version_info < (3, 10):
44+
from typing_extensions import ParamSpec
45+
else:
46+
from typing import ParamSpec
47+
48+
with suppress(ImportError):
49+
from eval_type_backport import ForwardRef # noqa: F811
4850

4951

5052
__all__ = (

news/+771c3a9d.fixed.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Support for 3.9 with `eval_type_backport`.

poetry.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test_class_singledispatch.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
import enum
44
import sys
5+
from contextlib import suppress
56
from dataclasses import dataclass
6-
from typing import Type
7+
from typing import ForwardRef, Type
78

89
import pytest
910

1011
from class_singledispatch import class_singledispatch, resolve_annotated_type
1112

12-
13-
try:
14-
from eval_type_backport import ForwardRef # type: ignore # noqa: PGH003
15-
except ImportError:
16-
from typing import ForwardRef # type: ignore # noqa: PGH003
13+
with suppress(ImportError):
14+
from eval_type_backport import ForwardRef
1715

1816

1917
@dataclass

0 commit comments

Comments
 (0)