|
1 |
| -import sys |
2 | 1 | import abc
|
3 |
| -import gc |
4 |
| -import io |
5 |
| -import contextlib |
6 | 2 | import collections
|
7 |
| -from collections import defaultdict |
8 | 3 | import collections.abc
|
| 4 | +import contextlib |
9 | 5 | import copy
|
10 |
| -from functools import lru_cache |
| 6 | +import gc |
11 | 7 | import importlib
|
12 | 8 | import inspect
|
| 9 | +import io |
13 | 10 | import pickle
|
14 | 11 | import re
|
15 | 12 | import subprocess
|
| 13 | +import sys |
16 | 14 | import tempfile
|
17 | 15 | import textwrap
|
18 | 16 | import types
|
19 |
| -from pathlib import Path |
20 |
| -from unittest import TestCase, main, skipUnless, skipIf |
21 |
| -from unittest.mock import patch |
22 | 17 | import typing
|
23 | 18 | import warnings
|
| 19 | +from collections import defaultdict |
| 20 | +from functools import lru_cache |
| 21 | +from pathlib import Path |
| 22 | +from unittest import TestCase, main, skipIf, skipUnless |
| 23 | +from unittest.mock import patch |
24 | 24 |
|
25 | 25 | import typing_extensions
|
26 |
| -from typing_extensions import NoReturn, Any, ClassVar, Final, IntVar, Literal, Type, NewType, TypedDict, Self |
27 |
| -from typing_extensions import TypeAlias, ParamSpec, Concatenate, ParamSpecArgs, ParamSpecKwargs, TypeGuard |
28 |
| -from typing_extensions import Awaitable, AsyncIterator, AsyncContextManager, Required, NotRequired, ReadOnly |
29 |
| -from typing_extensions import Protocol, runtime, runtime_checkable, Annotated, final, is_typeddict |
30 |
| -from typing_extensions import TypeVarTuple, Unpack, dataclass_transform, reveal_type, Never, assert_never, LiteralString |
31 |
| -from typing_extensions import assert_type, get_type_hints, get_origin, get_args, get_original_bases |
32 |
| -from typing_extensions import clear_overloads, get_overloads, overload, Iterator |
33 |
| -from typing_extensions import NamedTuple, TypeIs, no_type_check, Dict |
34 |
| -from typing_extensions import override, deprecated, Buffer, TypeAliasType, TypeVar, get_protocol_members, is_protocol |
35 |
| -from typing_extensions import Doc, NoDefault, List, Union, AnyStr, Iterable, Generic, Optional, Set, Tuple, Callable |
36 | 26 | from _typed_dict_test_helper import Foo, FooGeneric, VeryAnnotated
|
| 27 | +from typing_extensions import ( |
| 28 | + Annotated, |
| 29 | + Any, |
| 30 | + AnyStr, |
| 31 | + AsyncContextManager, |
| 32 | + AsyncIterator, |
| 33 | + Awaitable, |
| 34 | + Buffer, |
| 35 | + Callable, |
| 36 | + ClassVar, |
| 37 | + Concatenate, |
| 38 | + Dict, |
| 39 | + Doc, |
| 40 | + Final, |
| 41 | + Generic, |
| 42 | + IntVar, |
| 43 | + Iterable, |
| 44 | + Iterator, |
| 45 | + List, |
| 46 | + Literal, |
| 47 | + LiteralString, |
| 48 | + NamedTuple, |
| 49 | + Never, |
| 50 | + NewType, |
| 51 | + NoDefault, |
| 52 | + NoReturn, |
| 53 | + NotRequired, |
| 54 | + Optional, |
| 55 | + ParamSpec, |
| 56 | + ParamSpecArgs, |
| 57 | + ParamSpecKwargs, |
| 58 | + Protocol, |
| 59 | + ReadOnly, |
| 60 | + Required, |
| 61 | + Self, |
| 62 | + Set, |
| 63 | + Tuple, |
| 64 | + Type, |
| 65 | + TypeAlias, |
| 66 | + TypeAliasType, |
| 67 | + TypedDict, |
| 68 | + TypeGuard, |
| 69 | + TypeIs, |
| 70 | + TypeVar, |
| 71 | + TypeVarTuple, |
| 72 | + Union, |
| 73 | + Unpack, |
| 74 | + assert_never, |
| 75 | + assert_type, |
| 76 | + clear_overloads, |
| 77 | + dataclass_transform, |
| 78 | + deprecated, |
| 79 | + final, |
| 80 | + get_args, |
| 81 | + get_origin, |
| 82 | + get_original_bases, |
| 83 | + get_overloads, |
| 84 | + get_protocol_members, |
| 85 | + get_type_hints, |
| 86 | + is_protocol, |
| 87 | + is_typeddict, |
| 88 | + no_type_check, |
| 89 | + overload, |
| 90 | + override, |
| 91 | + reveal_type, |
| 92 | + runtime, |
| 93 | + runtime_checkable, |
| 94 | +) |
37 | 95 |
|
38 | 96 | NoneType = type(None)
|
39 | 97 | T = TypeVar("T")
|
@@ -179,14 +237,14 @@ def g_bad_ann():
|
179 | 237 | class BaseTestCase(TestCase):
|
180 | 238 | def assertIsSubclass(self, cls, class_or_tuple, msg=None):
|
181 | 239 | if not issubclass(cls, class_or_tuple):
|
182 |
| - message = f'{cls!r} is not a subclass of {repr(class_or_tuple)}' |
| 240 | + message = f'{cls!r} is not a subclass of {class_or_tuple!r}' |
183 | 241 | if msg is not None:
|
184 | 242 | message += f' : {msg}'
|
185 | 243 | raise self.failureException(message)
|
186 | 244 |
|
187 | 245 | def assertNotIsSubclass(self, cls, class_or_tuple, msg=None):
|
188 | 246 | if issubclass(cls, class_or_tuple):
|
189 |
| - message = f'{cls!r} is a subclass of {repr(class_or_tuple)}' |
| 247 | + message = f'{cls!r} is a subclass of {class_or_tuple!r}' |
190 | 248 | if msg is not None:
|
191 | 249 | message += f' : {msg}'
|
192 | 250 | raise self.failureException(message)
|
@@ -765,11 +823,11 @@ def test_repr(self):
|
765 | 823 | mod_name = 'typing'
|
766 | 824 | else:
|
767 | 825 | mod_name = 'typing_extensions'
|
768 |
| - self.assertEqual(repr(Required), mod_name + '.Required') |
| 826 | + self.assertEqual(repr(Required), f'{mod_name}.Required') |
769 | 827 | cv = Required[int]
|
770 |
| - self.assertEqual(repr(cv), mod_name + '.Required[int]') |
| 828 | + self.assertEqual(repr(cv), f'{mod_name}.Required[int]') |
771 | 829 | cv = Required[Employee]
|
772 |
| - self.assertEqual(repr(cv), mod_name + '.Required[%s.Employee]' % __name__) |
| 830 | + self.assertEqual(repr(cv), f'{mod_name}.Required[{__name__}.Employee]') |
773 | 831 |
|
774 | 832 | def test_cannot_subclass(self):
|
775 | 833 | with self.assertRaises(TypeError):
|
@@ -810,11 +868,11 @@ def test_repr(self):
|
810 | 868 | mod_name = 'typing'
|
811 | 869 | else:
|
812 | 870 | mod_name = 'typing_extensions'
|
813 |
| - self.assertEqual(repr(NotRequired), mod_name + '.NotRequired') |
| 871 | + self.assertEqual(repr(NotRequired), f'{mod_name}.NotRequired') |
814 | 872 | cv = NotRequired[int]
|
815 |
| - self.assertEqual(repr(cv), mod_name + '.NotRequired[int]') |
| 873 | + self.assertEqual(repr(cv), f'{mod_name}.NotRequired[int]') |
816 | 874 | cv = NotRequired[Employee]
|
817 |
| - self.assertEqual(repr(cv), mod_name + '.NotRequired[%s.Employee]' % __name__) |
| 875 | + self.assertEqual(repr(cv), f'{mod_name}.NotRequired[{ __name__}.Employee]') |
818 | 876 |
|
819 | 877 | def test_cannot_subclass(self):
|
820 | 878 | with self.assertRaises(TypeError):
|
@@ -872,7 +930,7 @@ def test_illegal_parameters_do_not_raise_runtime_errors(self):
|
872 | 930 | Literal[int]
|
873 | 931 | Literal[Literal[1, 2], Literal[4, 5]]
|
874 | 932 | Literal[3j + 2, ..., ()]
|
875 |
| - Literal[b"foo", u"bar"] |
| 933 | + Literal[b"foo", "bar"] |
876 | 934 | Literal[{"foo": 3, "bar": 4}]
|
877 | 935 | Literal[T]
|
878 | 936 |
|
@@ -1747,7 +1805,7 @@ class D: ...
|
1747 | 1805 | self.assertIsSubclass(D, A)
|
1748 | 1806 | self.assertIsSubclass(D, B)
|
1749 | 1807 |
|
1750 |
| - class M(): ... |
| 1808 | + class M: ... |
1751 | 1809 | collections.abc.Generator.register(M)
|
1752 | 1810 | self.assertIsSubclass(M, typing_extensions.Generator)
|
1753 | 1811 |
|
@@ -2988,7 +3046,7 @@ class NonP(P):
|
2988 | 3046 | class NonPR(PR): pass
|
2989 | 3047 | class C(metaclass=abc.ABCMeta):
|
2990 | 3048 | x = 1
|
2991 |
| - class D(metaclass=abc.ABCMeta): # noqa: B024 |
| 3049 | + class D(metaclass=abc.ABCMeta): |
2992 | 3050 | def meth(self): pass # noqa: B027
|
2993 | 3051 | self.assertNotIsInstance(C(), NonP)
|
2994 | 3052 | self.assertNotIsInstance(D(), NonPR)
|
@@ -3274,7 +3332,7 @@ def test_none_treated_correctly(self):
|
3274 | 3332 | @runtime_checkable
|
3275 | 3333 | class P(Protocol):
|
3276 | 3334 | x: int = None
|
3277 |
| - class B(object): pass |
| 3335 | + class B: pass |
3278 | 3336 | self.assertNotIsInstance(B(), P)
|
3279 | 3337 | class C:
|
3280 | 3338 | x = 1
|
@@ -5243,7 +5301,7 @@ def test_repr(self):
|
5243 | 5301 | mod_name = 'typing'
|
5244 | 5302 | else:
|
5245 | 5303 | mod_name = 'typing_extensions'
|
5246 |
| - self.assertEqual(repr(LiteralString), '{}.LiteralString'.format(mod_name)) |
| 5304 | + self.assertEqual(repr(LiteralString), f'{mod_name}.LiteralString') |
5247 | 5305 |
|
5248 | 5306 | def test_cannot_subscript(self):
|
5249 | 5307 | with self.assertRaises(TypeError):
|
@@ -5297,7 +5355,7 @@ def test_repr(self):
|
5297 | 5355 | mod_name = 'typing'
|
5298 | 5356 | else:
|
5299 | 5357 | mod_name = 'typing_extensions'
|
5300 |
| - self.assertEqual(repr(Self), '{}.Self'.format(mod_name)) |
| 5358 | + self.assertEqual(repr(Self), f'{mod_name}.Self') |
5301 | 5359 |
|
5302 | 5360 | def test_cannot_subscript(self):
|
5303 | 5361 | with self.assertRaises(TypeError):
|
@@ -5556,7 +5614,7 @@ def stmethod(): ...
|
5556 | 5614 | def prop(self): ...
|
5557 | 5615 |
|
5558 | 5616 | @final
|
5559 |
| - @lru_cache() # noqa: B019 |
| 5617 | + @lru_cache # noqa: B019 |
5560 | 5618 | def cached(self): ...
|
5561 | 5619 |
|
5562 | 5620 | # Use getattr_static because the descriptor returns the
|
@@ -6312,8 +6370,8 @@ def test_or(self):
|
6312 | 6370 | X = TypeVar('X')
|
6313 | 6371 | # use a string because str doesn't implement
|
6314 | 6372 | # __or__/__ror__ itself
|
6315 |
| - self.assertEqual(X | "x", Union[X, "x"]) # noqa: F821 |
6316 |
| - self.assertEqual("x" | X, Union["x", X]) # noqa: F821 |
| 6373 | + self.assertEqual(X | "x", Union[X, "x"]) |
| 6374 | + self.assertEqual("x" | X, Union["x", X]) |
6317 | 6375 | # make sure the order is correct
|
6318 | 6376 | self.assertEqual(get_args(X | "x"), (X, typing.ForwardRef("x")))
|
6319 | 6377 | self.assertEqual(get_args("x" | X), (typing.ForwardRef("x"), X))
|
|
0 commit comments