Debian Codegraph @

test-data/unit/fixtures/typing-typeddict-iror.pyi

raw
1 # Test stub for typing module that includes TypedDict `|` operator.
2 # It only covers `__or__`, `__ror__`, and `__ior__`.
3 #
4 # We cannot define these methods in `typing-typeddict.pyi`,
5 # because they need `dict` with two type args,
6 # and not all tests using `[typing typing-typeddict.pyi]` have the proper
7 # `dict` stub.
8 #
9 # Keep in sync with `typeshed`'s definition.
10 from abc import ABCMeta
11
12 cast = 0
13 assert_type = 0
14 overload = 0
15 Any = object()
16 Union = 0
17 Optional = 0
18 TypeVar = 0
19 Generic = 0
20 Protocol = 0
21 Tuple = 0
22 Callable = 0
23 NamedTuple = 0
24 Final = 0
25 Literal = 0
26 TypedDict = 0
27 NoReturn = 0
28 Required = 0
29 NotRequired = 0
30 Self = 0
31
32 T = TypeVar('T')
33 T_co = TypeVar('T_co', covariant=True)
34 V = TypeVar('V')
35
36 # Note: definitions below are different from typeshed, variances are declared
37 # to silence the protocol variance checks. Maybe it is better to use type: ignore?
38
39 class Sized(Protocol):
40 def __len__(self) -> int: pass
41
42 class Iterable(Protocol[T_co]):
43 def __iter__(self) -> 'Iterator[T_co]': pass
44
45 class Iterator(Iterable[T_co], Protocol):
46 def __next__(self) -> T_co: pass
47
48 class Sequence(Iterable[T_co]):
49 # misc is for explicit Any.
50 def __getitem__(self, n: Any) -> T_co: pass # type: ignore[misc]
51
52 class Mapping(Iterable[T], Generic[T, T_co], metaclass=ABCMeta):
53 pass
54
55 # Fallback type for all typed dicts (does not exist at runtime).
56 class _TypedDict(Mapping[str, object]):
57 @overload
58 def __or__(self, __value: Self) -> Self: ...
59 @overload
60 def __or__(self, __value: dict[str, Any]) -> dict[str, object]: ...
61 @overload
62 def __ror__(self, __value: Self) -> Self: ...
63 @overload
64 def __ror__(self, __value: dict[str, Any]) -> dict[str, object]: ...
65 # supposedly incompatible definitions of __or__ and __ior__
66 def __ior__(self, __value: Self) -> Self: ... # type: ignore[misc]
67
68 class _SpecialForm: pass