|
6 | 6 | from dataclasses import fields as dataclass_fields
|
7 | 7 | from dataclasses import is_dataclass
|
8 | 8 | from typing import AbstractSet as TypingAbstractSet
|
9 |
| -from typing import Any, Deque, Dict, FrozenSet, List |
| 9 | +from typing import Any, Deque, Dict, Final, FrozenSet, List |
10 | 10 | from typing import Mapping as TypingMapping
|
11 | 11 | from typing import MutableMapping as TypingMutableMapping
|
12 | 12 | from typing import MutableSequence as TypingMutableSequence
|
13 | 13 | from typing import MutableSet as TypingMutableSet
|
14 |
| -from typing import NewType, Optional |
| 14 | +from typing import NewType, Optional, Protocol |
15 | 15 | from typing import Sequence as TypingSequence
|
16 | 16 | from typing import Set as TypingSet
|
17 |
| -from typing import Tuple, get_type_hints |
| 17 | +from typing import Tuple, get_args, get_origin, get_type_hints |
18 | 18 |
|
19 |
| -from attr import NOTHING, Attribute, Factory |
20 |
| -from attr import fields as attrs_fields |
21 |
| -from attr import resolve_types |
| 19 | +from attrs import NOTHING, Attribute, Factory |
| 20 | +from attrs import fields as attrs_fields |
| 21 | +from attrs import resolve_types |
22 | 22 |
|
23 | 23 | __all__ = ["ExceptionGroup", "ExtensionsTypedDict", "TypedDict", "is_typeddict"]
|
24 | 24 |
|
|
27 | 27 | except ImportError:
|
28 | 28 | ExtensionsTypedDict = None
|
29 | 29 |
|
30 |
| -if sys.version_info >= (3, 8): |
31 |
| - from typing import Final, Protocol, get_args, get_origin |
32 |
| - |
33 |
| -else: |
34 |
| - |
35 |
| - def get_args(cl): |
36 |
| - return cl.__args__ |
37 |
| - |
38 |
| - def get_origin(cl): |
39 |
| - return getattr(cl, "__origin__", None) |
40 |
| - |
41 |
| - from typing_extensions import Final, Protocol |
42 | 30 |
|
43 | 31 | if sys.version_info >= (3, 11):
|
44 | 32 | from builtins import ExceptionGroup
|
@@ -355,16 +343,11 @@ def get_full_type_hints(obj, globalns=None, localns=None):
|
355 | 343 | TupleSubscriptable = Tuple
|
356 | 344 |
|
357 | 345 | from collections import Counter as ColCounter
|
358 |
| - from typing import Counter, Union, _GenericAlias |
| 346 | + from typing import Counter, TypedDict, Union, _GenericAlias |
359 | 347 |
|
360 | 348 | from typing_extensions import Annotated, NotRequired, Required
|
361 | 349 | from typing_extensions import get_origin as te_get_origin
|
362 | 350 |
|
363 |
| - if sys.version_info >= (3, 8): |
364 |
| - from typing import TypedDict |
365 |
| - else: |
366 |
| - TypedDict = ExtensionsTypedDict |
367 |
| - |
368 | 351 | def is_annotated(type) -> bool:
|
369 | 352 | return te_get_origin(type) is Annotated
|
370 | 353 |
|
@@ -440,16 +423,10 @@ def is_counter(type):
|
440 | 423 | or getattr(type, "__origin__", None) is ColCounter
|
441 | 424 | )
|
442 | 425 |
|
443 |
| - if sys.version_info >= (3, 8): |
444 |
| - from typing import Literal |
445 |
| - |
446 |
| - def is_literal(type) -> bool: |
447 |
| - return type.__class__ is _GenericAlias and type.__origin__ is Literal |
| 426 | + from typing import Literal |
448 | 427 |
|
449 |
| - else: |
450 |
| - # No literals in 3.7. |
451 |
| - def is_literal(_) -> bool: |
452 |
| - return False |
| 428 | + def is_literal(type) -> bool: |
| 429 | + return type.__class__ is _GenericAlias and type.__origin__ is Literal |
453 | 430 |
|
454 | 431 | def is_generic(obj):
|
455 | 432 | return isinstance(obj, _GenericAlias)
|
|
0 commit comments