| 1 |
# Builtins stub used in dictionary-related test cases (more complete). |
| 2 |
|
| 3 |
from _typeshed import SupportsKeysAndGetItem |
| 4 |
import _typeshed |
| 5 |
from typing import ( |
| 6 |
TypeVar, Generic, Iterable, Iterator, Mapping, Tuple, overload, Optional, Union, Sequence, |
| 7 |
Self, |
| 8 |
) |
| 9 |
|
| 10 |
T = TypeVar('T') |
| 11 |
T2 = TypeVar('T2') |
| 12 |
KT = TypeVar('KT') |
| 13 |
VT = TypeVar('VT') |
| 14 |
|
| 15 |
class object: |
| 16 |
__class__: object |
| 17 |
def __init__(self) -> None: pass |
| 18 |
def __init_subclass__(cls) -> None: pass |
| 19 |
def __eq__(self, other: object) -> bool: pass |
| 20 |
|
| 21 |
class type: |
| 22 |
__annotations__: Mapping[str, object] |
| 23 |
|
| 24 |
class dict(Mapping[KT, VT]): |
| 25 |
@overload |
| 26 |
def __init__(self, **kwargs: VT) -> None: pass |
| 27 |
@overload |
| 28 |
def __init__(self, arg: Iterable[Tuple[KT, VT]], **kwargs: VT) -> None: pass |
| 29 |
def __getitem__(self, key: KT) -> VT: pass |
| 30 |
def __setitem__(self, k: KT, v: VT) -> None: pass |
| 31 |
def __iter__(self) -> Iterator[KT]: pass |
| 32 |
def __contains__(self, item: object) -> int: pass |
| 33 |
def update(self, a: SupportsKeysAndGetItem[KT, VT]) -> None: pass |
| 34 |
@overload |
| 35 |
def get(self, key: KT, default: None = None, /) -> Optional[VT]: pass |
| 36 |
@overload |
| 37 |
def get(self, key: KT, default: VT, /) -> VT: pass |
| 38 |
@overload |
| 39 |
def get(self, key: KT, default: T, /) -> Union[VT, T]: pass |
| 40 |
def __len__(self) -> int: ... |
| 41 |
|
| 42 |
# This was actually added in 3.9: |
| 43 |
@overload |
| 44 |
def __or__(self, __value: dict[KT, VT]) -> dict[KT, VT]: ... |
| 45 |
@overload |
| 46 |
def __or__(self, __value: dict[T, T2]) -> dict[Union[KT, T], Union[VT, T2]]: ... |
| 47 |
@overload |
| 48 |
def __ror__(self, __value: dict[KT, VT]) -> dict[KT, VT]: ... |
| 49 |
@overload |
| 50 |
def __ror__(self, __value: dict[T, T2]) -> dict[Union[KT, T], Union[VT, T2]]: ... |
| 51 |
# dict.__ior__ should be kept roughly in line with MutableMapping.update() |
| 52 |
@overload # type: ignore[misc] |
| 53 |
def __ior__(self, __value: _typeshed.SupportsKeysAndGetItem[KT, VT]) -> Self: ... |
| 54 |
@overload |
| 55 |
def __ior__(self, __value: Iterable[Tuple[KT, VT]]) -> Self: ... |
| 56 |
|
| 57 |
class int: # for convenience |
| 58 |
def __add__(self, x: Union[int, complex]) -> int: pass |
| 59 |
def __radd__(self, x: int) -> int: pass |
| 60 |
def __sub__(self, x: Union[int, complex]) -> int: pass |
| 61 |
def __neg__(self) -> int: pass |
| 62 |
real: int |
| 63 |
imag: int |
| 64 |
|
| 65 |
class str: pass # for keyword argument key type |
| 66 |
class bytes: pass |
| 67 |
|
| 68 |
class list(Sequence[T]): # needed by some test cases |
| 69 |
def __getitem__(self, x: int) -> T: pass |
| 70 |
def __iter__(self) -> Iterator[T]: pass |
| 71 |
def __mul__(self, x: int) -> list[T]: pass |
| 72 |
def __contains__(self, item: object) -> bool: pass |
| 73 |
def append(self, item: T) -> None: pass |
| 74 |
|
| 75 |
class tuple(Generic[T]): pass |
| 76 |
class function: pass |
| 77 |
class float: pass |
| 78 |
class complex: pass |
| 79 |
class bool(int): pass |
| 80 |
|
| 81 |
class ellipsis: pass |
| 82 |
def isinstance(x: object, t: Union[type, Tuple[type, ...]]) -> bool: pass |
| 83 |
class BaseException: pass |
| 84 |
|
| 85 |
def iter(__iterable: Iterable[T]) -> Iterator[T]: pass |