Lines Matching defs:typing

15 from typing import Any, NoReturn, Never, assert_never
16 from typing import overload, get_overloads, clear_overloads
17 from typing import TypeVar, TypeVarTuple, Unpack, AnyStr
18 from typing import T, KT, VT # Not in __all__.
19 from typing import Union, Optional, Literal
20 from typing import Tuple, List, Dict, MutableMapping
21 from typing import Callable
22 from typing import Generic, ClassVar, Final, final, Protocol
23 from typing import assert_type, cast, runtime_checkable
24 from typing import get_type_hints
25 from typing import get_origin, get_args
26 from typing import is_typeddict
27 from typing import reveal_type
28 from typing import dataclass_transform
29 from typing import no_type_check, no_type_check_decorator
30 from typing import Type
31 from typing import NamedTuple, NotRequired, Required, TypedDict
32 from typing import IO, TextIO, BinaryIO
33 from typing import Pattern, Match
34 from typing import Annotated, ForwardRef
35 from typing import Self, LiteralString
36 from typing import TypeAlias
37 from typing import ParamSpec, Concatenate, ParamSpecArgs, ParamSpecKwargs
38 from typing import TypeGuard
41 import typing
50 py_typing = import_helper.import_fresh_module('typing', blocked=['_typing'])
51 c_typing = import_helper.import_fresh_module('typing', fresh=['_typing'])
53 CANNOT_SUBCLASS_TYPE = 'Cannot subclass special typing classes'
73 for f in typing._cleanups:
112 self.assertEqual(repr(Any), 'typing.Any')
150 typing.Match[Any]
151 typing.Pattern[Any]
152 typing.IO[Any]
199 self.assertEqual(repr(NoReturn), 'typing.NoReturn')
203 def some_str(arg: 'NoReturn') -> 'typing.NoReturn': ...
219 self.assertEqual(repr(Never), 'typing.Never')
223 def some_str(arg: 'Never') -> 'typing.Never': ...
246 typing._ASSERT_NEVER_REPR_MAX_LENGTH * 2,
262 def bar(self) -> 'typing.Self': ...
270 self.assertEqual(repr(Self), 'typing.Self')
318 def bar(self) -> 'typing.LiteralString': ...
326 self.assertEqual(repr(LiteralString), 'typing.LiteralString')
474 code = ("import typing\n"
475 "T = typing.TypeVar('T')\n"
718 # runtime lenient so people can experiment with typing constructs".
1079 self.assertEqual(repr(Tuple[Unpack[Ts]]), 'typing.Tuple[*Ts]')
1082 self.assertEqual(repr(Unpack[Tuple[Unpack[Ts]]]), '*typing.Tuple[*Ts]')
1099 'B[*typing.Tuple[int, ...]]')
1104 'A[float, *typing.Tuple[int, ...]]')
1109 'B[*typing.Tuple[int, ...], str]')
1114 'B[float, *typing.Tuple[int, ...], str]')
1175 self.assertEndsWith(repr(K), 'A[*Ts, *typing.Tuple[str, ...]]')
1176 self.assertEndsWith(repr(K[()]), 'A[*typing.Tuple[str, ...]]')
1177 self.assertEndsWith(repr(K[float]), 'A[float, *typing.Tuple[str, ...]]')
1178 self.assertEndsWith(repr(K[float, str]), 'A[float, str, *typing.Tuple[str, ...]]')
1195 r'Cannot subclass typing\.Unpack'):
1503 # Unpacking using `Unpack`, `Tuple` type from typing.py
1709 self.assertEqual(repr(Union), 'typing.Union')
1711 self.assertEqual(repr(u), 'typing.Union[%s.Employee, int]' % __name__)
1713 self.assertEqual(repr(u), 'typing.Union[int, %s.Employee]' % __name__)
1718 self.assertEqual(repr(u), 'typing.Union[typing.List[int], int]')
1720 self.assertEqual(repr(u), 'typing.Union[list[int], dict[str, float]]')
1722 self.assertEqual(repr(u), 'typing.Union[int, float]')
1725 self.assertEqual(repr(u), 'typing.Optional[str]')
1727 self.assertEqual(repr(u), 'typing.Optional[str]')
1729 self.assertEqual(repr(u), 'typing.Union[NoneType, str, int]')
1731 self.assertEqual(repr(u), 'typing.Optional[str]')
1764 self.assertFalse(Union[str, typing.Iterable[int]] == str)
1765 self.assertFalse(Union[str, typing.Iterable[int]] == typing.Iterable[int])
1766 self.assertIn(str, Union[str, typing.Iterable[int]].__args__)
1767 self.assertIn(typing.Iterable[int], Union[str, typing.Iterable[int]].__args__)
1775 self.assertNotEqual(Optional, typing.Mapping)
1776 self.assertNotEqual(Optional[typing.MutableMapping], Union)
1794 self.assertEqual(repr(Union[fun, int]), 'typing.Union[fun, int]')
1802 # See https://github.com/python/typing/issues/229
1874 self.assertEqual(repr(Tuple), 'typing.Tuple')
1875 self.assertEqual(repr(Tuple[()]), 'typing.Tuple[()]')
1876 self.assertEqual(repr(Tuple[int, float]), 'typing.Tuple[int, float]')
1877 self.assertEqual(repr(Tuple[int, ...]), 'typing.Tuple[int, ...]')
1878 self.assertEqual(repr(Tuple[list[int]]), 'typing.Tuple[list[int]]')
1976 # Shouldn't crash; see https://github.com/python/typing/issues/259
1977 typing.List[Callable[..., str]]
2041 # substitute a nested GenericAlias (both typing and the builtin
2043 C5 = Callable[[typing.List[T], tuple[KT, T], VT], int]
2045 Callable[[typing.List[int], tuple[str, int], float], int])
2108 f"{fullname}[typing.Concatenate[int, ~P], ~T]")
2118 f"{fullname}[typing.Concatenate[int, ~P], int]")
2182 Callable = typing.Callable
2186 # Testing collections.abc.Callable's consistency with typing.Callable
2187 c1 = typing.Callable[[int, str], dict]
2229 self.assertEqual(repr(Literal[1]), "typing.Literal[1]")
2230 self.assertEqual(repr(Literal[1, True, "foo"]), "typing.Literal[1, True, 'foo']")
2231 self.assertEqual(repr(Literal[int]), "typing.Literal[int]")
2232 self.assertEqual(repr(Literal), "typing.Literal")
2233 self.assertEqual(repr(Literal[None]), "typing.Literal[None]")
2234 self.assertEqual(repr(Literal[1, 2, 3, 3]), "typing.Literal[1, 2, 3]")
2399 __call__: typing.Callable
2438 for thing in (object(), 1, (), typing, f):
3116 class P(typing.Mapping[T, S], Protocol[T]): pass
3171 self.assertEqual(typing._get_protocol_attrs(P), {'meth'})
3172 self.assertEqual(typing._get_protocol_attrs(PR), {'x'})
3173 self.assertEqual(frozenset(typing._get_protocol_attrs(PG)),
3222 Alias = typing.Union[typing.Iterable, P]
3223 Alias2 = typing.Union[P, typing.Iterable]
3256 self.assertIsSubclass(int, typing.SupportsInt)
3257 self.assertNotIsSubclass(str, typing.SupportsInt)
3260 self.assertIsSubclass(float, typing.SupportsFloat)
3261 self.assertNotIsSubclass(str, typing.SupportsFloat)
3269 self.assertIsSubclass(complex, typing.SupportsComplex)
3270 self.assertIsSubclass(C, typing.SupportsComplex)
3271 self.assertNotIsSubclass(str, typing.SupportsComplex)
3279 self.assertIsSubclass(bytes, typing.SupportsBytes)
3280 self.assertIsSubclass(B, typing.SupportsBytes)
3281 self.assertNotIsSubclass(str, typing.SupportsBytes)
3284 self.assertIsSubclass(float, typing.SupportsAbs)
3285 self.assertIsSubclass(int, typing.SupportsAbs)
3286 self.assertNotIsSubclass(str, typing.SupportsAbs)
3289 issubclass(float, typing.SupportsRound)
3290 self.assertIsSubclass(float, typing.SupportsRound)
3291 self.assertIsSubclass(int, typing.SupportsRound)
3292 self.assertNotIsSubclass(str, typing.SupportsRound)
3295 self.assertIsSubclass(list, typing.Reversible)
3296 self.assertNotIsSubclass(int, typing.Reversible)
3299 self.assertIsSubclass(int, typing.SupportsIndex)
3300 self.assertNotIsSubclass(str, typing.SupportsIndex)
3303 self.assertIsInstance(0, typing.SupportsAbs)
3304 class C1(typing.SupportsInt):
3332 class CustomContextManager(typing.ContextManager, Protocol):
3408 class X(typing.Generic[T]):
3455 '.C[typing.Tuple[str, int]]'))
3462 self.assertEqual(repr(List), 'typing.List')
3463 self.assertEqual(repr(List[T]), 'typing.List[~T]')
3464 self.assertEqual(repr(List[U]), 'typing.List[+U]')
3465 self.assertEqual(repr(List[S][T][int]), 'typing.List[int]')
3466 self.assertEqual(repr(List[int]), 'typing.List[int]')
3472 self.assertEqual(repr(typing.Mapping[T, TS][TS, T]), 'typing.Mapping[~TS, ~T]')
3474 'typing.List[typing.Tuple[int, ~T]]')
3477 'typing.List[typing.Tuple[typing.List[int], typing.List[int]]]'
3482 self.assertEqual(repr(Generic[T]), 'typing.Generic[~T]')
3483 self.assertEqual(repr(typing.Protocol[T]), 'typing.Protocol[~T]')
3484 class C(typing.Dict[Any, Any]): ...
3575 class C(typing.Dict[str, T]): ...
3576 self.assertEqual(C.__orig_bases__, (typing.Dict[str, T],))
3589 self.assertTrue(naive_dict_check({'x': 1}, typing.Dict[str, int]))
3590 self.assertFalse(naive_dict_check({1: 'x'}, typing.Dict[str, int]))
3592 naive_dict_check({1: 'x'}, typing.Dict[str, T])
3670 self.assertNotEqual(typing.FrozenSet[A[str]],
3671 typing.FrozenSet[mod_generics_cache.B.A[str]])
3684 self.assertEqual(typing.Iterable[Tuple[T, T]][T], typing.Iterable[Tuple[T, T]])
3698 self.assertEqual(repr(Union[Tuple, Callable]).replace('typing.', ''),
3700 self.assertEqual(repr(Union[Tuple, Tuple[int]]).replace('typing.', ''),
3702 self.assertEqual(repr(Callable[..., Optional[T]][int]).replace('typing.', ''),
3704 self.assertEqual(repr(Callable[[], List[T]][int]).replace('typing.', ''),
3775 class C1(typing.Container[T]):
3797 issubclass(Tuple[int, ...], typing.Sequence)
3799 issubclass(Tuple[int, ...], typing.Iterable)
3818 List[typing.Protocol]
3827 class MyDict(typing.Dict[T, T]): ...
3830 class MyDef(typing.DefaultDict[str, T]): ...
3833 class MyChain(typing.ChainMap[str, T]): ...
3838 objs = (getattr(typing, el) for el in typing.__all__)
3843 and not isinstance(obj, typing.TypeVar)
3874 typing.DefaultDict, typing.FrozenSet[int]]
3880 more_samples = [List, typing.Iterable, typing.Type, List[int],
3881 typing.Type[typing.Mapping], typing.AbstractSet[Tuple[int, str]]]
3893 Tuple[Any, Any], Node[T], Node[int], Node[Any], typing.Iterable[T],
3894 typing.Iterable[Any], typing.Iterable[int], typing.Dict[int, str],
3895 typing.Dict[T, Any], ClassVar[int], ClassVar[List[T]], Tuple['T', 'T'],
3896 Union['T', int], List['T'], typing.Mapping['T', int]]
3910 List, typing.Mapping, ClassVar, typing.Iterable,
3956 Optional[List[int]], typing.Mapping[int, str],
3957 typing.Match[bytes], typing.Iterable['whatever']]
4093 V = Visitor[typing.List[int]]
4257 # Duck-typing anything that looks like it has __parameters__.
4300 self.assertEqual(repr(ClassVar), 'typing.ClassVar')
4302 self.assertEqual(repr(cv), 'typing.ClassVar[int]')
4304 self.assertEqual(repr(cv), 'typing.ClassVar[%s.Employee]' % __name__)
4340 self.assertEqual(repr(Final), 'typing.Final')
4342 self.assertEqual(repr(cv), 'typing.Final[int]')
4344 self.assertEqual(repr(cv), 'typing.Final[%s.Employee]' % __name__)
4346 self.assertEqual(repr(cv), 'typing.Final[tuple[int]]')
4529 fr = typing.ForwardRef('int')
4534 fr = typing.ForwardRef('int')
4540 typing.ForwardRef(1) # only `str` type is allowed
4543 fr = typing.ForwardRef('int')
4544 self.assertEqual(fr, typing.ForwardRef('int'))
4546 self.assertNotEqual(fr, typing.ForwardRef('int', module=__name__))
4547 frm = typing.ForwardRef('int', module=__name__)
4548 self.assertEqual(frm, typing.ForwardRef('int', module=__name__))
4549 self.assertNotEqual(frm, typing.ForwardRef('int', module='__other_name__'))
4552 c1 = typing.ForwardRef('C')
4553 c1_gth = typing.ForwardRef('C')
4554 c2 = typing.ForwardRef('C')
4555 c2_gth = typing.ForwardRef('C')
4573 c1 = typing.ForwardRef('int')
4574 c1_gth = typing.ForwardRef('int')
4575 c2 = typing.ForwardRef('int')
4576 c2_gth = typing.ForwardRef('int')
4586 c3 = typing.ForwardRef('int', module=__name__)
4587 c4 = typing.ForwardRef('int', module='__other_name__')
4592 self.assertEqual(hash(c3), hash(typing.ForwardRef('int', module=__name__)))
4598 a = typing.ForwardRef('A')
4605 a = typing.ForwardRef('A')
4619 self.assertEqual(repr(List['int']), "typing.List[ForwardRef('int')]")
4621 "typing.List[ForwardRef('int', module='mod')]")
4659 a = typing.ForwardRef('A')
4667 a = typing.ForwardRef('A')
4890 foo: typing.ClassVar[int] = 7
4894 foo: 'typing.ClassVar[int]' = 7
4898 expected_result = {'foo': typing.ClassVar[int]}
4904 foo: 'typing.ClassVar[typing.ClassVar[int]]' = 7
4996 with patch("typing._overload_registry",
4999 self.assertEqual(typing._overload_registry, {})
5006 self.assertEqual(typing.get_overloads(sum), [])
5007 self.assertEqual(typing.get_overloads(print), [])
5028 @patch("typing._overload_registry",
5032 self.assertEqual(typing._overload_registry, {})
5035 self.assertNotEqual(typing._overload_registry, {})
5050 self.assertEqual(typing._overload_registry, {})
5056 self.assertEqual(typing._overload_registry, {})
5071 class AwaitableWrapper(typing.Awaitable[T_a]):
5076 def __await__(self) -> typing.Iterator[T_a]:
5080 class AsyncIteratorWrapper(typing.AsyncIterator[T_a]):
5082 def __init__(self, value: typing.Iterable[T_a]):
5085 def __aiter__(self) -> typing.AsyncIterator[T_a]:
5198 async def g_with(am: typing.AsyncContextManager[int]):
5239 # FIXME: This currently exposes a bug in typing. Cached forward references
5316 {'var': typing.ClassVar[ann_module2.CV]})
5368 def barfoo2(x: typing.Callable[..., Annotated[List[T], "const"]],
5369 y: typing.Union[int, Annotated[T, "mutable"]]): ...
5372 {'x': typing.Callable[..., List[T]], 'y': typing.Union[int, T]}
5375 BA2 = typing.Callable[..., List[T]]
5381 BA3 = typing.Annotated[int | float, "const"]
5389 {"x": typing.Annotated[int | float, "const"]}
5477 r'typing.ClassVar\[int\] is not valid as type argument',
5578 self.assertEqual(get_args(typing.Dict[int, Tuple[T, T]][Optional[int]]),
5619 self.assertIsInstance(42, typing.Hashable)
5620 self.assertNotIsInstance([], typing.Hashable)
5623 self.assertIsInstance([], typing.Iterable)
5626 self.assertIsInstance([], typing.Iterable)
5627 self.assertIsInstance([], typing.Iterable)
5628 self.assertNotIsInstance(42, typing.Iterable)
5630 self.assertIsSubclass(list, typing.Iterable)
5631 self.assertIsSubclass(list, typing.Iterable)
5635 self.assertIsInstance(it, typing.Iterator)
5636 self.assertNotIsInstance(42, typing.Iterator)
5641 "async def foo() -> typing.Awaitable[int]:\n"
5646 self.assertIsInstance(g, typing.Awaitable)
5647 self.assertNotIsInstance(foo, typing.Awaitable)
5658 self.assertIsInstance(g, typing.Coroutine)
5660 isinstance(g, typing.Coroutine[int])
5661 self.assertNotIsInstance(foo, typing.Coroutine)
5670 self.assertIsInstance(it, typing.AsyncIterable)
5671 self.assertIsInstance(it, typing.AsyncIterable)
5672 self.assertNotIsInstance(42, typing.AsyncIterable)
5677 self.assertIsInstance(it, typing.AsyncIterator)
5678 self.assertNotIsInstance(42, typing.AsyncIterator)
5681 self.assertIsInstance([], typing.Sized)
5682 self.assertNotIsInstance(42, typing.Sized)
5685 self.assertIsInstance([], typing.Container)
5686 self.assertNotIsInstance(42, typing.Container)
5689 self.assertIsInstance(tuple(), typing.Collection)
5690 self.assertIsInstance(frozenset(), typing.Collection)
5691 self.assertIsSubclass(dict, typing.Collection)
5692 self.assertNotIsInstance(42, typing.Collection)
5695 self.assertIsInstance(set(), typing.AbstractSet)
5696 self.assertNotIsInstance(42, typing.AbstractSet)
5699 self.assertIsInstance(set(), typing.MutableSet)
5700 self.assertNotIsInstance(frozenset(), typing.MutableSet)
5703 self.assertIsInstance({}, typing.Mapping)
5704 self.assertNotIsInstance(42, typing.Mapping)
5707 self.assertIsInstance({}, typing.MutableMapping)
5708 self.assertNotIsInstance(42, typing.MutableMapping)
5711 self.assertIsInstance([], typing.Sequence)
5712 self.assertNotIsInstance(42, typing.Sequence)
5715 self.assertIsInstance([], typing.MutableSequence)
5716 self.assertNotIsInstance((), typing.MutableSequence)
5719 self.assertIsInstance(b'', typing.ByteString)
5720 self.assertIsInstance(bytearray(b''), typing.ByteString)
5723 self.assertIsSubclass(list, typing.List)
5726 self.assertIsSubclass(collections.deque, typing.Deque)
5727 class MyDeque(typing.Deque[int]): ...
5731 self.assertIsSubclass(collections.Counter, typing.Counter)
5734 self.assertIsSubclass(set, typing.Set)
5735 self.assertNotIsSubclass(frozenset, typing.Set)
5738 self.assertIsSubclass(frozenset, typing.FrozenSet)
5739 self.assertNotIsSubclass(set, typing.FrozenSet)
5742 self.assertIsSubclass(dict, typing.Dict)
5757 typing.List()
5759 typing.List[T]()
5761 typing.List[int]()
5765 class MyList(typing.List[int]):
5770 self.assertIsInstance(a, typing.Sequence)
5777 typing.Dict()
5779 typing.Dict[KT, VT]()
5781 typing.Dict[str, int]()
5785 class MyDict(typing.Dict[str, int]):
5790 self.assertIsInstance(d, typing.MutableMapping)
5796 self.assertIs(type(typing.DefaultDict()), collections.defaultdict)
5797 self.assertIs(type(typing.DefaultDict[KT, VT]()), collections.defaultdict)
5798 self.assertIs(type(typing.DefaultDict[str, int]()), collections.defaultdict)
5802 class MyDefDict(typing.DefaultDict[str, int]):
5812 self.assertIs(type(typing.OrderedDict()), collections.OrderedDict)
5813 self.assertIs(type(typing.OrderedDict[KT, VT]()), collections.OrderedDict)
5814 self.assertIs(type(typing.OrderedDict[str, int]()), collections.OrderedDict)
5818 class MyOrdDict(typing.OrderedDict[str, int]):
5828 self.assertIs(type(typing.ChainMap()), collections.ChainMap)
5829 self.assertIs(type(typing.ChainMap[KT, VT]()), collections.ChainMap)
5830 self.assertIs(type(typing.ChainMap[str, int]()), collections.ChainMap)
5831 class CM(typing.ChainMap[KT, VT]): ...
5836 class MyChainMap(typing.ChainMap[str, int]):
5846 self.assertIs(type(typing.Deque()), collections.deque)
5847 self.assertIs(type(typing.Deque[T]()), collections.deque)
5848 self.assertIs(type(typing.Deque[int]()), collections.deque)
5849 class D(typing.Deque[T]): ...
5853 self.assertIs(type(typing.Counter()), collections.Counter)
5854 self.assertIs(type(typing.Counter[T]()), collections.Counter)
5855 self.assertIs(type(typing.Counter[int]()), collections.Counter)
5856 class C(typing.Counter[T]): ...
5861 class MyCounter(typing.Counter[int]):
5866 self.assertIsInstance(d, typing.Counter)
5871 typing.Set()
5873 typing.Set[T]()
5875 typing.Set[int]()
5879 class MySet(typing.Set[int]):
5887 typing.FrozenSet()
5889 typing.FrozenSet[T]()
5891 typing.FrozenSet[int]()
5895 class MyFrozenSet(typing.FrozenSet[int]):
5913 self.assertIsSubclass(type(g), typing.Generator)
5917 typing.Generator()
5919 typing.Generator[T, T, T]()
5921 typing.Generator[int, int, int]()
5928 self.assertIsSubclass(type(g), typing.AsyncGenerator)
5932 typing.AsyncGenerator()
5934 typing.AsyncGenerator[T, T]()
5936 typing.AsyncGenerator[int, int]()
5940 class MMA(typing.MutableMapping):
5960 self.assertIsInstance(MMC(), typing.Mapping)
5962 class MMB(typing.MutableMapping[KT, VT]):
5981 self.assertIsSubclass(MMA, typing.Mapping)
5982 self.assertIsSubclass(MMB, typing.Mapping)
5983 self.assertIsSubclass(MMC, typing.Mapping)
5985 self.assertIsInstance(MMB[KT, VT](), typing.Mapping)
5993 issubclass(MMB[str, str], typing.Mapping)
5996 class I(typing.Iterable): ...
5999 class G(typing.Generator[int, int, int]): ...
6001 self.assertIsSubclass(G, typing.Generator)
6002 self.assertIsSubclass(G, typing.Iterable)
6008 class G(typing.AsyncGenerator[int, int]):
6017 self.assertIsSubclass(G, typing.AsyncGenerator)
6018 self.assertIsSubclass(G, typing.AsyncIterable)
6024 self.assertIsInstance(instance, typing.AsyncGenerator)
6025 self.assertIsInstance(instance, typing.AsyncIterable)
6033 class Base(typing.Iterable):
6050 class A(typing.Container): ...
6065 self.assertIsSubclass(M, typing.Mapping)
6070 self.assertIsSubclass(M, typing.Mapping)
6071 self.assertIsSubclass(M, typing.Iterable)
6074 self.assertIsSubclass(S, typing.MutableSequence)
6075 self.assertIsSubclass(S, typing.Iterable)
6078 self.assertIsSubclass(I, typing.Iterable)
6083 self.assertIsSubclass(B, typing.Mapping)
6086 self.assertEqual(typing.Sized | typing.Awaitable, Union[typing.Sized, typing.Awaitable])
6087 self.assertEqual(typing.Coroutine | typing.Hashable, Union[typing.Coroutine, typing.Hashable])
6098 self.assertIsInstance(cm, typing.ContextManager)
6099 self.assertNotIsInstance(42, typing.ContextManager)
6104 self.assertIsInstance(ACM(), typing.AsyncContextManager)
6105 self.assertNotIsInstance(NotACM(), typing.AsyncContextManager)
6111 self.assertNotIsInstance(cm, typing.AsyncContextManager)
6112 self.assertEqual(typing.AsyncContextManager[int].__args__, (int,))
6114 isinstance(42, typing.AsyncContextManager[int])
6116 typing.AsyncContextManager[int, str]
6163 self.assertEqual(getattr(py_typing, fname).__module__, 'typing')
6178 sys.modules['typing'] = cls.module
6188 sys.modules['typing'] = typing
6248 code = ("import typing\n"
6249 "NT = typing.NewType('NT', int)\n"
6475 self.assertIsSubclass(Emp, typing.MutableMapping)
6495 self.assertIsSubclass(Emp, typing.MutableMapping)
6532 self.assertEqual(TypedDict.__module__, 'typing')
6549 self.assertNotIsSubclass(LabelPoint2D, typing.Sequence)
6583 self.assertEqual(typing.Optional[EmpD], typing.Union[None, EmpD])
6584 self.assertNotEqual(typing.List[EmpD], typing.Tuple[EmpD])
6788 {'a': typing.Optional[int], 'b': int}
6794 {'a': typing.Optional[T], 'b': int}
6802 {'a': typing.Optional[T], 'b': int, 'c': str}
6934 self.assertEqual(repr(Required), 'typing.Required')
6936 self.assertEqual(repr(cv), 'typing.Required[int]')
6938 self.assertEqual(repr(cv), f'typing.Required[{__name__}.Employee]')
6980 self.assertEqual(repr(NotRequired), 'typing.NotRequired')
6982 self.assertEqual(repr(cv), 'typing.NotRequired[int]')
6984 self.assertEqual(repr(cv), f'typing.NotRequired[{__name__}.Employee]')
7044 from typing.io import IO, TextIO, BinaryIO, __all__, __name__
7045 self.assertIs(IO, typing.IO)
7046 self.assertIs(TextIO, typing.TextIO)
7047 self.assertIs(BinaryIO, typing.BinaryIO)
7049 self.assertEqual(__name__, 'typing.io')
7089 self.assertEqual(repr(Pattern), 'typing.Pattern')
7090 self.assertEqual(repr(Pattern[str]), 'typing.Pattern[str]')
7091 self.assertEqual(repr(Pattern[bytes]), 'typing.Pattern[bytes]')
7092 self.assertEqual(repr(Match), 'typing.Match')
7093 self.assertEqual(repr(Match[str]), 'typing.Match[str]')
7094 self.assertEqual(repr(Match[bytes]), 'typing.Match[bytes]')
7099 from typing.re import Match, Pattern, __all__, __name__
7100 self.assertIs(Match, typing.Match)
7101 self.assertIs(Pattern, typing.Pattern)
7103 self.assertEqual(__name__, 'typing.re')
7109 class A(typing.Match):
7128 "typing.Annotated[int, 4, 5]"
7132 "typing.Annotated[typing.List[int], 4, 5]"
7191 MyCount = Annotated[typing.Counter[T], "my decoration"]
7244 samples = [typing.Any, typing.Union[int, str],
7245 typing.Optional[str], Tuple[int, ...],
7246 typing.Callable[[str], bytes]]
7289 D = Annotated[typing.Dict[KT, VT], dec]
7290 self.assertEqual(D[str, int], Annotated[typing.Dict[str, int], dec])
7463 self.assertEqual(repr(TypeAlias), 'typing.TypeAlias')
7672 typing.Callable[P, T][arg, str]
7902 self.assertEqual(repr(TypeGuard), 'typing.TypeGuard')
7904 self.assertEqual(repr(cv), 'typing.TypeGuard[int]')
7906 self.assertEqual(repr(cv), 'typing.TypeGuard[%s.Employee]' % __name__)
7908 self.assertEqual(repr(cv), 'typing.TypeGuard[tuple[int]]')
7933 SpecialAttrsP = typing.ParamSpec('SpecialAttrsP')
7934 SpecialAttrsT = typing.TypeVar('SpecialAttrsT', int, float, complex)
7942 typing.AbstractSet: 'AbstractSet',
7943 typing.AsyncContextManager: 'AsyncContextManager',
7944 typing.AsyncGenerator: 'AsyncGenerator',
7945 typing.AsyncIterable: 'AsyncIterable',
7946 typing.AsyncIterator: 'AsyncIterator',
7947 typing.Awaitable: 'Awaitable',
7948 typing.ByteString: 'ByteString',
7949 typing.Callable: 'Callable',
7950 typing.ChainMap: 'ChainMap',
7951 typing.Collection: 'Collection',
7952 typing.Container: 'Container',
7953 typing.ContextManager: 'ContextManager',
7954 typing.Coroutine: 'Coroutine',
7955 typing.Counter: 'Counter',
7956 typing.DefaultDict: 'DefaultDict',
7957 typing.Deque: 'Deque',
7958 typing.Dict: 'Dict',
7959 typing.FrozenSet: 'FrozenSet',
7960 typing.Generator: 'Generator',
7961 typing.Hashable: 'Hashable',
7962 typing.ItemsView: 'ItemsView',
7963 typing.Iterable: 'Iterable',
7964 typing.Iterator: 'Iterator',
7965 typing.KeysView: 'KeysView',
7966 typing.List: 'List',
7967 typing.Mapping: 'Mapping',
7968 typing.MappingView: 'MappingView',
7969 typing.MutableMapping: 'MutableMapping',
7970 typing.MutableSequence: 'MutableSequence',
7971 typing.MutableSet: 'MutableSet',
7972 typing.OrderedDict: 'OrderedDict',
7973 typing.Reversible: 'Reversible',
7974 typing.Sequence: 'Sequence',
7975 typing.Set: 'Set',
7976 typing.Sized: 'Sized',
7977 typing.Tuple: 'Tuple',
7978 typing.Type: 'Type',
7979 typing.ValuesView: 'ValuesView',
7981 typing.AbstractSet[Any]: 'AbstractSet',
7982 typing.AsyncContextManager[Any]: 'AsyncContextManager',
7983 typing.AsyncGenerator[Any, Any]: 'AsyncGenerator',
7984 typing.AsyncIterable[Any]: 'AsyncIterable',
7985 typing.AsyncIterator[Any]: 'AsyncIterator',
7986 typing.Awaitable[Any]: 'Awaitable',
7987 typing.Callable[[], Any]: 'Callable',
7988 typing.Callable[..., Any]: 'Callable',
7989 typing.ChainMap[Any, Any]: 'ChainMap',
7990 typing.Collection[Any]: 'Collection',
7991 typing.Container[Any]: 'Container',
7992 typing.ContextManager[Any]: 'ContextManager',
7993 typing.Coroutine[Any, Any, Any]: 'Coroutine',
7994 typing.Counter[Any]: 'Counter',
7995 typing.DefaultDict[Any, Any]: 'DefaultDict',
7996 typing.Deque[Any]: 'Deque',
7997 typing.Dict[Any, Any]: 'Dict',
7998 typing.FrozenSet[Any]: 'FrozenSet',
7999 typing.Generator[Any, Any, Any]: 'Generator',
8000 typing.ItemsView[Any, Any]: 'ItemsView',
8001 typing.Iterable[Any]: 'Iterable',
8002 typing.Iterator[Any]: 'Iterator',
8003 typing.KeysView[Any]: 'KeysView',
8004 typing.List[Any]: 'List',
8005 typing.Mapping[Any, Any]: 'Mapping',
8006 typing.MappingView[Any]: 'MappingView',
8007 typing.MutableMapping[Any, Any]: 'MutableMapping',
8008 typing.MutableSequence[Any]: 'MutableSequence',
8009 typing.MutableSet[Any]: 'MutableSet',
8010 typing.OrderedDict[Any, Any]: 'OrderedDict',
8011 typing.Reversible[Any]: 'Reversible',
8012 typing.Sequence[Any]: 'Sequence',
8013 typing.Set[Any]: 'Set',
8014 typing.Tuple[Any]: 'Tuple',
8015 typing.Tuple[Any, ...]: 'Tuple',
8016 typing.Type[Any]: 'Type',
8017 typing.ValuesView[Any]: 'ValuesView',
8019 typing.Annotated: 'Annotated',
8020 typing.Any: 'Any',
8021 typing.ClassVar: 'ClassVar',
8022 typing.Concatenate: 'Concatenate',
8023 typing.Final: 'Final',
8024 typing.ForwardRef: 'ForwardRef',
8025 typing.Literal: 'Literal',
8026 typing.NewType: 'NewType',
8027 typing.NoReturn: 'NoReturn',
8028 typing.Never: 'Never',
8029 typing.Optional: 'Optional',
8030 typing.TypeAlias: 'TypeAlias',
8031 typing.TypeGuard: 'TypeGuard',
8032 typing.TypeVar: 'TypeVar',
8033 typing.Union: 'Union',
8034 typing.Self: 'Self',
8036 typing.Annotated[Any, "Annotation"]: 'Annotated',
8037 typing.ClassVar[Any]: 'ClassVar',
8038 typing.Concatenate[Any, SpecialAttrsP]: 'Concatenate',
8039 typing.Final[Any]: 'Final',
8040 typing.Literal[Any]: 'Literal',
8041 typing.Literal[1, 2]: 'Literal',
8042 typing.Literal[True, 2]: 'Literal',
8043 typing.Optional[Any]: 'Optional',
8044 typing.TypeGuard[Any]: 'TypeGuard',
8045 typing.Union[Any]: 'Any',
8046 typing.Union[int, float]: 'Union',
8048 # - typing.ForwardRef('set[Any]')
8049 # - typing.NewType('TypeName', Any)
8050 # - typing.ParamSpec('SpecialAttrsP')
8051 # - typing.TypeVar('T')
8058 self.assertEqual(cls.__module__, 'typing', str(cls))
8064 TypeName = typing.NewType('SpecialAttrsTests.TypeName', Any)
8069 # complex typing expressions.
8070 fr = typing.ForwardRef('set[Any]')
8073 self.assertEqual(fr.__module__, 'typing')
8232 from typing import __all__ as a
8254 actual_all = set(typing.__all__)
8256 k for k, v in vars(typing).items()
8265 # but export all things that have __module__ == 'typing'
8266 getattr(v, '__module__', None) == typing.__name__