ir.py 13 KB

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