ir.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. # These builtins stubs are used implicitly in AST to IR generation
  2. # test cases.
  3. import _typeshed
  4. from typing import (
  5. TypeVar, Generic, List, Iterator, Iterable, Dict, Optional, Tuple, Any, Set,
  6. overload, Mapping, Union, Callable, Sequence, FrozenSet, Protocol
  7. )
  8. T = TypeVar('T')
  9. T_co = TypeVar('T_co', covariant=True)
  10. T_contra = TypeVar('T_contra', contravariant=True)
  11. S = TypeVar('S')
  12. K = TypeVar('K') # for keys in mapping
  13. V = TypeVar('V') # for values in mapping
  14. class __SupportsAbs(Protocol[T_co]):
  15. def __abs__(self) -> T_co: pass
  16. class __SupportsDivMod(Protocol[T_contra, T_co]):
  17. def __divmod__(self, other: T_contra) -> T_co: ...
  18. class __SupportsRDivMod(Protocol[T_contra, T_co]):
  19. def __rdivmod__(self, other: T_contra) -> T_co: ...
  20. _M = TypeVar("_M", contravariant=True)
  21. class __SupportsPow2(Protocol[T_contra, T_co]):
  22. def __pow__(self, other: T_contra) -> T_co: ...
  23. class __SupportsPow3NoneOnly(Protocol[T_contra, T_co]):
  24. def __pow__(self, other: T_contra, modulo: None = ...) -> T_co: ...
  25. class __SupportsPow3(Protocol[T_contra, _M, T_co]):
  26. def __pow__(self, other: T_contra, modulo: _M) -> T_co: ...
  27. __SupportsSomeKindOfPow = Union[
  28. __SupportsPow2[Any, Any], __SupportsPow3NoneOnly[Any, Any] | __SupportsPow3[Any, Any, Any]
  29. ]
  30. class object:
  31. def __init__(self) -> None: pass
  32. def __eq__(self, x: object) -> bool: pass
  33. def __ne__(self, x: object) -> bool: pass
  34. class type:
  35. def __init__(self, o: object) -> None: ...
  36. __name__ : str
  37. __annotations__: Dict[str, Any]
  38. class ellipsis: pass
  39. # Primitive types are special in generated code.
  40. class int:
  41. @overload
  42. def __init__(self) -> None: pass
  43. @overload
  44. def __init__(self, x: object, base: int = 10) -> None: pass
  45. def __add__(self, n: int) -> int: pass
  46. def __sub__(self, n: int) -> int: pass
  47. def __mul__(self, n: int) -> int: pass
  48. def __pow__(self, n: int, modulo: Optional[int] = None) -> int: pass
  49. def __floordiv__(self, x: int) -> int: pass
  50. def __truediv__(self, x: float) -> float: pass
  51. def __mod__(self, x: int) -> int: pass
  52. def __divmod__(self, x: float) -> Tuple[float, float]: pass
  53. def __neg__(self) -> int: pass
  54. def __pos__(self) -> int: pass
  55. def __abs__(self) -> int: pass
  56. def __invert__(self) -> int: pass
  57. def __and__(self, n: int) -> int: pass
  58. def __or__(self, n: int) -> int: pass
  59. def __xor__(self, n: int) -> int: pass
  60. def __lshift__(self, x: int) -> int: pass
  61. def __rshift__(self, x: int) -> int: pass
  62. def __eq__(self, n: object) -> bool: pass
  63. def __ne__(self, n: object) -> bool: pass
  64. def __lt__(self, n: int) -> bool: pass
  65. def __gt__(self, n: int) -> bool: pass
  66. def __le__(self, n: int) -> bool: pass
  67. def __ge__(self, n: int) -> bool: pass
  68. class str:
  69. @overload
  70. def __init__(self) -> None: pass
  71. @overload
  72. def __init__(self, x: object) -> None: pass
  73. def __add__(self, x: str) -> str: pass
  74. def __mul__(self, x: int) -> str: pass
  75. def __rmul__(self, x: int) -> str: pass
  76. def __eq__(self, x: object) -> bool: pass
  77. def __ne__(self, x: object) -> bool: pass
  78. def __lt__(self, x: str) -> bool: ...
  79. def __le__(self, x: str) -> bool: ...
  80. def __gt__(self, x: str) -> bool: ...
  81. def __ge__(self, x: str) -> bool: ...
  82. @overload
  83. def __getitem__(self, i: int) -> str: pass
  84. @overload
  85. def __getitem__(self, i: slice) -> str: pass
  86. def __contains__(self, item: str) -> bool: pass
  87. def __iter__(self) -> Iterator[str]: ...
  88. def split(self, sep: Optional[str] = None, max: Optional[int] = None) -> List[str]: pass
  89. def strip (self, item: str) -> str: pass
  90. def join(self, x: Iterable[str]) -> str: pass
  91. def format(self, *args: Any, **kwargs: Any) -> str: ...
  92. def upper(self) -> str: ...
  93. def startswith(self, x: str, start: int=..., end: int=...) -> bool: ...
  94. def endswith(self, x: str, start: int=..., end: int=...) -> bool: ...
  95. def replace(self, old: str, new: str, maxcount: int=...) -> str: ...
  96. def encode(self, x: str=..., y: str=...) -> bytes: ...
  97. class float:
  98. def __init__(self, x: object) -> None: pass
  99. def __add__(self, n: float) -> float: pass
  100. def __radd__(self, n: float) -> float: pass
  101. def __sub__(self, n: float) -> float: pass
  102. def __rsub__(self, n: float) -> float: pass
  103. def __mul__(self, n: float) -> float: pass
  104. def __truediv__(self, n: float) -> float: pass
  105. def __floordiv__(self, n: float) -> float: pass
  106. def __mod__(self, n: float) -> float: pass
  107. def __pow__(self, n: float) -> float: pass
  108. def __neg__(self) -> float: pass
  109. def __pos__(self) -> float: pass
  110. def __abs__(self) -> float: pass
  111. def __invert__(self) -> float: pass
  112. def __eq__(self, x: object) -> bool: pass
  113. def __ne__(self, x: object) -> bool: pass
  114. def __lt__(self, x: float) -> bool: ...
  115. def __le__(self, x: float) -> bool: ...
  116. def __gt__(self, x: float) -> bool: ...
  117. def __ge__(self, x: float) -> bool: ...
  118. class complex:
  119. def __init__(self, x: object, y: object = None) -> None: pass
  120. def __add__(self, n: complex) -> complex: pass
  121. def __radd__(self, n: float) -> complex: pass
  122. def __sub__(self, n: complex) -> complex: pass
  123. def __rsub__(self, n: float) -> complex: pass
  124. def __mul__(self, n: complex) -> complex: pass
  125. def __truediv__(self, n: complex) -> complex: pass
  126. def __neg__(self) -> complex: pass
  127. class bytes:
  128. @overload
  129. def __init__(self) -> None: ...
  130. @overload
  131. def __init__(self, x: object) -> None: ...
  132. def __add__(self, x: bytes) -> bytes: ...
  133. def __mul__(self, x: int) -> bytes: ...
  134. def __rmul__(self, x: int) -> bytes: ...
  135. def __eq__(self, x: object) -> bool: ...
  136. def __ne__(self, x: object) -> bool: ...
  137. @overload
  138. def __getitem__(self, i: int) -> int: ...
  139. @overload
  140. def __getitem__(self, i: slice) -> bytes: ...
  141. def join(self, x: Iterable[object]) -> bytes: ...
  142. def decode(self, x: str=..., y: str=...) -> str: ...
  143. class bytearray:
  144. @overload
  145. def __init__(self) -> None: pass
  146. @overload
  147. def __init__(self, x: object) -> None: pass
  148. @overload
  149. def __init__(self, string: str, encoding: str, err: str = ...) -> None: pass
  150. def __add__(self, s: bytes) -> bytearray: ...
  151. def __setitem__(self, i: int, o: int) -> None: ...
  152. def __getitem__(self, i: int) -> int: ...
  153. def decode(self, x: str = ..., y: str = ...) -> str: ...
  154. class bool(int):
  155. def __init__(self, o: object = ...) -> None: ...
  156. @overload
  157. def __and__(self, n: bool) -> bool: ...
  158. @overload
  159. def __and__(self, n: int) -> int: ...
  160. @overload
  161. def __or__(self, n: bool) -> bool: ...
  162. @overload
  163. def __or__(self, n: int) -> int: ...
  164. @overload
  165. def __xor__(self, n: bool) -> bool: ...
  166. @overload
  167. def __xor__(self, n: int) -> int: ...
  168. class tuple(Generic[T_co], Sequence[T_co], Iterable[T_co]):
  169. def __init__(self, i: Iterable[T_co]) -> None: pass
  170. @overload
  171. def __getitem__(self, i: int) -> T_co: pass
  172. @overload
  173. def __getitem__(self, i: slice) -> Tuple[T_co, ...]: pass
  174. def __len__(self) -> int: pass
  175. def __iter__(self) -> Iterator[T_co]: ...
  176. def __contains__(self, item: object) -> int: ...
  177. class function: pass
  178. class list(Generic[T], Sequence[T], Iterable[T]):
  179. def __init__(self, i: Optional[Iterable[T]] = None) -> None: pass
  180. @overload
  181. def __getitem__(self, i: int) -> T: ...
  182. @overload
  183. def __getitem__(self, s: slice) -> List[T]: ...
  184. def __setitem__(self, i: int, o: T) -> None: pass
  185. def __delitem__(self, i: int) -> None: pass
  186. def __mul__(self, i: int) -> List[T]: pass
  187. def __rmul__(self, i: int) -> List[T]: pass
  188. def __iter__(self) -> Iterator[T]: pass
  189. def __len__(self) -> int: pass
  190. def __contains__(self, item: object) -> int: ...
  191. def __add__(self, x: List[T]) -> List[T]: ...
  192. def append(self, x: T) -> None: pass
  193. def pop(self, i: int = -1) -> T: pass
  194. def count(self, T) -> int: pass
  195. def extend(self, l: Iterable[T]) -> None: pass
  196. def insert(self, i: int, x: T) -> None: pass
  197. def sort(self) -> None: pass
  198. def reverse(self) -> None: pass
  199. def remove(self, o: T) -> None: pass
  200. def index(self, o: T) -> int: pass
  201. class dict(Mapping[K, V]):
  202. @overload
  203. def __init__(self, **kwargs: K) -> None: ...
  204. @overload
  205. def __init__(self, map: Mapping[K, V], **kwargs: V) -> None: ...
  206. @overload
  207. def __init__(self, iterable: Iterable[Tuple[K, V]], **kwargs: V) -> None: ...
  208. def __getitem__(self, key: K) -> V: pass
  209. def __setitem__(self, k: K, v: V) -> None: pass
  210. def __delitem__(self, k: K) -> None: pass
  211. def __contains__(self, item: object) -> int: pass
  212. def __iter__(self) -> Iterator[K]: pass
  213. def __len__(self) -> int: pass
  214. @overload
  215. def update(self, __m: Mapping[K, V], **kwargs: V) -> None: pass
  216. @overload
  217. def update(self, __m: Iterable[Tuple[K, V]], **kwargs: V) -> None: ...
  218. @overload
  219. def update(self, **kwargs: V) -> None: ...
  220. def pop(self, x: int) -> K: pass
  221. def keys(self) -> Iterable[K]: pass
  222. def values(self) -> Iterable[V]: pass
  223. def items(self) -> Iterable[Tuple[K, V]]: pass
  224. def clear(self) -> None: pass
  225. def copy(self) -> Dict[K, V]: pass
  226. def setdefault(self, key: K, val: V = ...) -> V: pass
  227. class set(Generic[T]):
  228. def __init__(self, i: Optional[Iterable[T]] = None) -> None: pass
  229. def __iter__(self) -> Iterator[T]: pass
  230. def __len__(self) -> int: pass
  231. def add(self, x: T) -> None: pass
  232. def remove(self, x: T) -> None: pass
  233. def discard(self, x: T) -> None: pass
  234. def clear(self) -> None: pass
  235. def pop(self) -> T: pass
  236. def update(self, x: Iterable[S]) -> None: pass
  237. def __or__(self, s: Union[Set[S], FrozenSet[S]]) -> Set[Union[T, S]]: ...
  238. def __xor__(self, s: Union[Set[S], FrozenSet[S]]) -> Set[Union[T, S]]: ...
  239. class frozenset(Generic[T]):
  240. def __init__(self, i: Optional[Iterable[T]] = None) -> None: pass
  241. def __iter__(self) -> Iterator[T]: pass
  242. def __len__(self) -> int: pass
  243. def __or__(self, s: Union[Set[S], FrozenSet[S]]) -> FrozenSet[Union[T, S]]: ...
  244. def __xor__(self, s: Union[Set[S], FrozenSet[S]]) -> FrozenSet[Union[T, S]]: ...
  245. class slice: pass
  246. class range(Iterable[int]):
  247. def __init__(self, x: int, y: int = ..., z: int = ...) -> None: pass
  248. def __iter__(self) -> Iterator[int]: pass
  249. def __len__(self) -> int: pass
  250. def __next__(self) -> int: pass
  251. class property:
  252. def __init__(self, fget: Optional[Callable[[Any], Any]] = ...,
  253. fset: Optional[Callable[[Any, Any], None]] = ...,
  254. fdel: Optional[Callable[[Any], None]] = ...,
  255. doc: Optional[str] = ...) -> None: ...
  256. def getter(self, fget: Callable[[Any], Any]) -> property: ...
  257. def setter(self, fset: Callable[[Any, Any], None]) -> property: ...
  258. def deleter(self, fdel: Callable[[Any], None]) -> property: ...
  259. def __get__(self, obj: Any, type: Optional[type] = ...) -> Any: ...
  260. def __set__(self, obj: Any, value: Any) -> None: ...
  261. def __delete__(self, obj: Any) -> None: ...
  262. def fget(self) -> Any: ...
  263. def fset(self, value: Any) -> None: ...
  264. def fdel(self) -> None: ...
  265. class BaseException: pass
  266. class Exception(BaseException):
  267. def __init__(self, message: Optional[str] = None) -> None: pass
  268. class Warning(Exception): pass
  269. class UserWarning(Warning): pass
  270. class TypeError(Exception): pass
  271. class ValueError(Exception): pass
  272. class AttributeError(Exception): pass
  273. class ImportError(Exception): pass
  274. class NameError(Exception): pass
  275. class UnboundLocalError(NameError): pass
  276. class LookupError(Exception): pass
  277. class KeyError(LookupError): pass
  278. class IndexError(LookupError): pass
  279. class RuntimeError(Exception): pass
  280. class UnicodeEncodeError(RuntimeError): pass
  281. class UnicodeDecodeError(RuntimeError): pass
  282. class NotImplementedError(RuntimeError): pass
  283. class StopIteration(Exception):
  284. value: Any
  285. class ArithmeticError(Exception): pass
  286. class ZeroDivisionError(ArithmeticError): pass
  287. class OverflowError(ArithmeticError): pass
  288. class GeneratorExit(BaseException): pass
  289. def any(i: Iterable[T]) -> bool: pass
  290. def all(i: Iterable[T]) -> bool: pass
  291. def sum(i: Iterable[T]) -> int: pass
  292. def reversed(object: Sequence[T]) -> Iterator[T]: ...
  293. def id(o: object) -> int: pass
  294. # This type is obviously wrong but the test stubs don't have Sized anymore
  295. def len(o: object) -> int: pass
  296. def print(*object) -> None: pass
  297. def isinstance(x: object, t: object) -> bool: pass
  298. def iter(i: Iterable[T]) -> Iterator[T]: pass
  299. @overload
  300. def next(i: Iterator[T]) -> T: pass
  301. @overload
  302. def next(i: Iterator[T], default: T) -> T: pass
  303. def hash(o: object) -> int: ...
  304. def globals() -> Dict[str, Any]: ...
  305. def getattr(obj: object, name: str, default: Any = None) -> Any: ...
  306. def setattr(obj: object, name: str, value: Any) -> None: ...
  307. def enumerate(x: Iterable[T]) -> Iterator[Tuple[int, T]]: ...
  308. @overload
  309. def zip(x: Iterable[T], y: Iterable[S]) -> Iterator[Tuple[T, S]]: ...
  310. @overload
  311. def zip(x: Iterable[T], y: Iterable[S], z: Iterable[V]) -> Iterator[Tuple[T, S, V]]: ...
  312. def eval(e: str) -> Any: ...
  313. def abs(x: __SupportsAbs[T]) -> T: ...
  314. @overload
  315. def divmod(x: __SupportsDivMod[T_contra, T_co], y: T_contra) -> T_co: ...
  316. @overload
  317. def divmod(x: T_contra, y: __SupportsRDivMod[T_contra, T_co]) -> T_co: ...
  318. @overload
  319. def pow(base: __SupportsPow2[T_contra, T_co], exp: T_contra, mod: None = None) -> T_co: ...
  320. @overload
  321. def pow(base: __SupportsPow3NoneOnly[T_contra, T_co], exp: T_contra, mod: None = None) -> T_co: ...
  322. @overload
  323. def pow(base: __SupportsPow3[T_contra, _M, T_co], exp: T_contra, mod: _M) -> T_co: ...
  324. def exit() -> None: ...
  325. def min(x: T, y: T) -> T: ...
  326. def max(x: T, y: T) -> T: ...
  327. def repr(o: object) -> str: ...
  328. def ascii(o: object) -> str: ...
  329. def ord(o: object) -> int: ...
  330. def chr(i: int) -> str: ...
  331. # Dummy definitions.
  332. class classmethod: pass
  333. class staticmethod: pass
  334. NotImplemented: Any = ...