This commit is contained in:
Waylon Walker 2022-03-31 20:20:07 -05:00
commit 38355d2442
No known key found for this signature in database
GPG key ID: 66E2BF2B4190EFE4
9083 changed files with 1225834 additions and 0 deletions

View file

@ -0,0 +1,316 @@
# These builtins stubs are used implicitly in AST to IR generation
# test cases.
from typing import (
TypeVar, Generic, List, Iterator, Iterable, Dict, Optional, Tuple, Any, Set,
overload, Mapping, Union, Callable, Sequence,
)
T = TypeVar('T')
T_co = TypeVar('T_co', covariant=True)
S = TypeVar('S')
K = TypeVar('K') # for keys in mapping
V = TypeVar('V') # for values in mapping
class object:
def __init__(self) -> None: pass
def __eq__(self, x: object) -> bool: pass
def __ne__(self, x: object) -> bool: pass
class type:
def __init__(self, o: object) -> None: ...
__name__ : str
__annotations__: Dict[str, Any]
class ellipsis: pass
# Primitive types are special in generated code.
class int:
@overload
def __init__(self) -> None: pass
@overload
def __init__(self, x: object, base: int = 10) -> None: pass
def __add__(self, n: int) -> int: pass
def __sub__(self, n: int) -> int: pass
def __mul__(self, n: int) -> int: pass
def __pow__(self, n: int, modulo: Optional[int] = None) -> int: pass
def __floordiv__(self, x: int) -> int: pass
def __truediv__(self, x: float) -> float: pass
def __mod__(self, x: int) -> int: pass
def __neg__(self) -> int: pass
def __pos__(self) -> int: pass
def __invert__(self) -> int: pass
def __and__(self, n: int) -> int: pass
def __or__(self, n: int) -> int: pass
def __xor__(self, n: int) -> int: pass
def __lshift__(self, x: int) -> int: pass
def __rshift__(self, x: int) -> int: pass
def __eq__(self, n: object) -> bool: pass
def __ne__(self, n: object) -> bool: pass
def __lt__(self, n: int) -> bool: pass
def __gt__(self, n: int) -> bool: pass
def __le__(self, n: int) -> bool: pass
def __ge__(self, n: int) -> bool: pass
class str:
@overload
def __init__(self) -> None: pass
@overload
def __init__(self, x: object) -> None: pass
def __add__(self, x: str) -> str: pass
def __eq__(self, x: object) -> bool: pass
def __ne__(self, x: object) -> bool: pass
def __lt__(self, x: str) -> bool: ...
def __le__(self, x: str) -> bool: ...
def __gt__(self, x: str) -> bool: ...
def __ge__(self, x: str) -> bool: ...
@overload
def __getitem__(self, i: int) -> str: pass
@overload
def __getitem__(self, i: slice) -> str: pass
def __contains__(self, item: str) -> bool: pass
def __iter__(self) -> Iterator[str]: ...
def split(self, sep: Optional[str] = None, max: Optional[int] = None) -> List[str]: pass
def strip (self, item: str) -> str: pass
def join(self, x: Iterable[str]) -> str: pass
def format(self, *args: Any, **kwargs: Any) -> str: ...
def upper(self) -> str: ...
def startswith(self, x: str, start: int=..., end: int=...) -> bool: ...
def endswith(self, x: str, start: int=..., end: int=...) -> bool: ...
def replace(self, old: str, new: str, maxcount: int=...) -> str: ...
def encode(self, x: str=..., y: str=...) -> bytes: ...
class float:
def __init__(self, x: object) -> None: pass
def __add__(self, n: float) -> float: pass
def __sub__(self, n: float) -> float: pass
def __mul__(self, n: float) -> float: pass
def __truediv__(self, n: float) -> float: pass
def __neg__(self) -> float: pass
class complex:
def __init__(self, x: object, y: object = None) -> None: pass
def __add__(self, n: complex) -> complex: pass
def __sub__(self, n: complex) -> complex: pass
def __mul__(self, n: complex) -> complex: pass
def __truediv__(self, n: complex) -> complex: pass
def __neg__(self) -> complex: pass
class bytes:
@overload
def __init__(self) -> None: ...
@overload
def __init__(self, x: object) -> None: ...
def __add__(self, x: bytes) -> bytes: ...
def __eq__(self, x: object) -> bool: ...
def __ne__(self, x: object) -> bool: ...
@overload
def __getitem__(self, i: int) -> int: ...
@overload
def __getitem__(self, i: slice) -> bytes: ...
def join(self, x: Iterable[object]) -> bytes: ...
def decode(self, x: str=..., y: str=...) -> str: ...
class bytearray:
@overload
def __init__(self) -> None: pass
@overload
def __init__(self, x: object) -> None: pass
@overload
def __init__(self, string: str, encoding: str, err: str = ...) -> None: pass
def __add__(self, s: bytes) -> bytearray: ...
def __setitem__(self, i: int, o: int) -> None: ...
def __getitem__(self, i: int) -> int: ...
def decode(self, x: str = ..., y: str = ...) -> str: ...
class bool(int):
def __init__(self, o: object = ...) -> None: ...
@overload
def __and__(self, n: bool) -> bool: ...
@overload
def __and__(self, n: int) -> int: ...
@overload
def __or__(self, n: bool) -> bool: ...
@overload
def __or__(self, n: int) -> int: ...
@overload
def __xor__(self, n: bool) -> bool: ...
@overload
def __xor__(self, n: int) -> int: ...
class tuple(Generic[T_co], Sequence[T_co], Iterable[T_co]):
def __init__(self, i: Iterable[T_co]) -> None: pass
@overload
def __getitem__(self, i: int) -> T_co: pass
@overload
def __getitem__(self, i: slice) -> Tuple[T_co, ...]: pass
def __len__(self) -> int: pass
def __iter__(self) -> Iterator[T_co]: ...
def __contains__(self, item: object) -> int: ...
class function: pass
class list(Generic[T], Sequence[T], Iterable[T]):
def __init__(self, i: Optional[Iterable[T]] = None) -> None: pass
@overload
def __getitem__(self, i: int) -> T: ...
@overload
def __getitem__(self, s: slice) -> List[T]: ...
def __setitem__(self, i: int, o: T) -> None: pass
def __delitem__(self, i: int) -> None: pass
def __mul__(self, i: int) -> List[T]: pass
def __rmul__(self, i: int) -> List[T]: pass
def __iter__(self) -> Iterator[T]: pass
def __len__(self) -> int: pass
def __contains__(self, item: object) -> int: ...
def append(self, x: T) -> None: pass
def pop(self, i: int = -1) -> T: pass
def count(self, T) -> int: pass
def extend(self, l: Iterable[T]) -> None: pass
def insert(self, i: int, x: T) -> None: pass
def sort(self) -> None: pass
def reverse(self) -> None: pass
def remove(self, o: T) -> None: pass
def index(self, o: T) -> int: pass
class dict(Mapping[K, V]):
@overload
def __init__(self, **kwargs: K) -> None: ...
@overload
def __init__(self, map: Mapping[K, V], **kwargs: V) -> None: ...
@overload
def __init__(self, iterable: Iterable[Tuple[K, V]], **kwargs: V) -> None: ...
def __getitem__(self, key: K) -> V: pass
def __setitem__(self, k: K, v: V) -> None: pass
def __delitem__(self, k: K) -> None: pass
def __contains__(self, item: object) -> int: pass
def __iter__(self) -> Iterator[K]: pass
def __len__(self) -> int: pass
@overload
def update(self, __m: Mapping[K, V], **kwargs: V) -> None: pass
@overload
def update(self, __m: Iterable[Tuple[K, V]], **kwargs: V) -> None: ...
@overload
def update(self, **kwargs: V) -> None: ...
def pop(self, x: int) -> K: pass
def keys(self) -> Iterable[K]: pass
def values(self) -> Iterable[V]: pass
def items(self) -> Iterable[Tuple[K, V]]: pass
def clear(self) -> None: pass
def copy(self) -> Dict[K, V]: pass
def setdefault(self, key: K, val: V = ...) -> V: pass
class set(Generic[T]):
def __init__(self, i: Optional[Iterable[T]] = None) -> None: pass
def __iter__(self) -> Iterator[T]: pass
def __len__(self) -> int: pass
def add(self, x: T) -> None: pass
def remove(self, x: T) -> None: pass
def discard(self, x: T) -> None: pass
def clear(self) -> None: pass
def pop(self) -> T: pass
def update(self, x: Iterable[S]) -> None: pass
def __or__(self, s: Set[S]) -> Set[Union[T, S]]: ...
class slice: pass
class range(Iterable[int]):
def __init__(self, x: int, y: int = ..., z: int = ...) -> None: pass
def __iter__(self) -> Iterator[int]: pass
def __len__(self) -> int: pass
def __next__(self) -> int: pass
class property:
def __init__(self, fget: Optional[Callable[[Any], Any]] = ...,
fset: Optional[Callable[[Any, Any], None]] = ...,
fdel: Optional[Callable[[Any], None]] = ...,
doc: Optional[str] = ...) -> None: ...
def getter(self, fget: Callable[[Any], Any]) -> property: ...
def setter(self, fset: Callable[[Any, Any], None]) -> property: ...
def deleter(self, fdel: Callable[[Any], None]) -> property: ...
def __get__(self, obj: Any, type: Optional[type] = ...) -> Any: ...
def __set__(self, obj: Any, value: Any) -> None: ...
def __delete__(self, obj: Any) -> None: ...
def fget(self) -> Any: ...
def fset(self, value: Any) -> None: ...
def fdel(self) -> None: ...
class BaseException: pass
class Exception(BaseException):
def __init__(self, message: Optional[str] = None) -> None: pass
class Warning(Exception): pass
class UserWarning(Warning): pass
class TypeError(Exception): pass
class ValueError(Exception): pass
class AttributeError(Exception): pass
class ImportError(Exception): pass
class NameError(Exception): pass
class LookupError(Exception): pass
class KeyError(LookupError): pass
class IndexError(LookupError): pass
class RuntimeError(Exception): pass
class UnicodeEncodeError(RuntimeError): pass
class UnicodeDecodeError(RuntimeError): pass
class NotImplementedError(RuntimeError): pass
class StopIteration(Exception):
value: Any
class ArithmeticError(Exception): pass
class ZeroDivisionError(Exception): pass
def any(i: Iterable[T]) -> bool: pass
def all(i: Iterable[T]) -> bool: pass
def sum(i: Iterable[T]) -> int: pass
def reversed(object: Sequence[T]) -> Iterator[T]: ...
def id(o: object) -> int: pass
# This type is obviously wrong but the test stubs don't have Sized anymore
def len(o: object) -> int: pass
def print(*object) -> None: pass
def isinstance(x: object, t: object) -> bool: pass
def iter(i: Iterable[T]) -> Iterator[T]: pass
@overload
def next(i: Iterator[T]) -> T: pass
@overload
def next(i: Iterator[T], default: T) -> T: pass
def hash(o: object) -> int: ...
def globals() -> Dict[str, Any]: ...
def getattr(obj: object, name: str) -> Any: ...
def setattr(obj: object, name: str, value: Any) -> None: ...
def enumerate(x: Iterable[T]) -> Iterator[Tuple[int, T]]: ...
@overload
def zip(x: Iterable[T], y: Iterable[S]) -> Iterator[Tuple[T, S]]: ...
@overload
def zip(x: Iterable[T], y: Iterable[S], z: Iterable[V]) -> Iterator[Tuple[T, S, V]]: ...
def eval(e: str) -> Any: ...
def abs(x: float) -> float: ...
def exit() -> None: ...
def min(x: T, y: T) -> T: ...
def max(x: T, y: T) -> T: ...
def repr(o: object) -> str: ...
def ascii(o: object) -> str: ...
def ord(o: object) -> int: ...
def chr(i: int) -> str: ...
# Dummy definitions.
class classmethod: pass
class staticmethod: pass
NotImplemented: Any = ...

View file

@ -0,0 +1,52 @@
# Simple support library for our run tests.
from contextlib import contextmanager
from typing import (
Any, Iterator, TypeVar, Generator, Optional, List, Tuple, Sequence,
Union, Callable,
)
@contextmanager
def assertRaises(typ: type, msg: str = '') -> Iterator[None]:
try:
yield
except Exception as e:
assert isinstance(e, typ), "{} is not a {}".format(e, typ.__name__)
assert msg in str(e), 'Message "{}" does not match "{}"'.format(e, msg)
else:
assert False, "Expected {} but got no exception".format(typ.__name__)
T = TypeVar('T')
U = TypeVar('U')
V = TypeVar('V')
def run_generator(gen: Generator[T, V, U],
inputs: Optional[List[V]] = None,
p: bool = False) -> Tuple[Sequence[T], Union[U, str]]:
res: List[T] = []
i = -1
while True:
try:
if i >= 0 and inputs:
# ... fixtures don't have send
val = gen.send(inputs[i]) # type: ignore
else:
val = next(gen)
except StopIteration as e:
return (tuple(res), e.value)
except Exception as e:
return (tuple(res), str(e))
if p:
print(val)
res.append(val)
i += 1
F = TypeVar('F', bound=Callable)
# Wrap a mypyc-generated function in a real python function, to allow it to be
# stuck into classes and the like.
def make_python_function(f: F) -> F:
def g(*args: Any, **kwargs: Any) -> Any:
return f(*args, **kwargs)
return g # type: ignore

View file

@ -0,0 +1,168 @@
# More complete stub for typing module.
#
# Use [typing fixtures/typing-full.pyi] to use this instead of lib-stub/typing.pyi
# in a particular test case.
#
# Many of the definitions have special handling in the type checker, so they
# can just be initialized to anything.
from abc import abstractmethod, ABCMeta
class GenericMeta(type): pass
cast = 0
overload = 0
Any = 0
Union = 0
Optional = 0
TypeVar = 0
Generic = 0
Protocol = 0
Tuple = 0
Callable = 0
_promote = 0
NamedTuple = 0
Type = 0
no_type_check = 0
ClassVar = 0
Final = 0
Literal = 0
TypedDict = 0
NoReturn = 0
NewType = 0
T = TypeVar('T')
T_co = TypeVar('T_co', covariant=True)
T_contra = TypeVar('T_contra', contravariant=True)
U = TypeVar('U')
V = TypeVar('V')
S = TypeVar('S')
# Note: definitions below are different from typeshed, variances are declared
# to silence the protocol variance checks. Maybe it is better to use type: ignore?
@runtime_checkable
class Container(Protocol[T_co]):
@abstractmethod
# Use int because bool isn't in the default test builtins
def __contains__(self, arg: object) -> int: pass
@runtime_checkable
class Sized(Protocol):
@abstractmethod
def __len__(self) -> int: pass
@runtime_checkable
class Iterable(Protocol[T_co]):
@abstractmethod
def __iter__(self) -> 'Iterator[T_co]': pass
@runtime_checkable
class Iterator(Iterable[T_co], Protocol):
@abstractmethod
def __next__(self) -> T_co: pass
class Generator(Iterator[T], Generic[T, U, V]):
@abstractmethod
def send(self, value: U) -> T: pass
@abstractmethod
def throw(self, typ: Any, val: Any=None, tb: Any=None) -> None: pass
@abstractmethod
def close(self) -> None: pass
@abstractmethod
def __iter__(self) -> 'Generator[T, U, V]': pass
class AsyncGenerator(AsyncIterator[T], Generic[T, U]):
@abstractmethod
def __anext__(self) -> Awaitable[T]: pass
@abstractmethod
def asend(self, value: U) -> Awaitable[T]: pass
@abstractmethod
def athrow(self, typ: Any, val: Any=None, tb: Any=None) -> Awaitable[T]: pass
@abstractmethod
def aclose(self) -> Awaitable[T]: pass
@abstractmethod
def __aiter__(self) -> 'AsyncGenerator[T, U]': pass
@runtime_checkable
class Awaitable(Protocol[T]):
@abstractmethod
def __await__(self) -> Generator[Any, Any, T]: pass
class AwaitableGenerator(Generator[T, U, V], Awaitable[V], Generic[T, U, V, S], metaclass=ABCMeta):
pass
class Coroutine(Awaitable[V], Generic[T, U, V]):
@abstractmethod
def send(self, value: U) -> T: pass
@abstractmethod
def throw(self, typ: Any, val: Any=None, tb: Any=None) -> None: pass
@abstractmethod
def close(self) -> None: pass
@runtime_checkable
class AsyncIterable(Protocol[T]):
@abstractmethod
def __aiter__(self) -> 'AsyncIterator[T]': pass
@runtime_checkable
class AsyncIterator(AsyncIterable[T], Protocol):
def __aiter__(self) -> 'AsyncIterator[T]': return self
@abstractmethod
def __anext__(self) -> Awaitable[T]: pass
class Sequence(Iterable[T_co], Container[T_co]):
@abstractmethod
def __getitem__(self, n: Any) -> T_co: pass
class Mapping(Iterable[T], Generic[T, T_co], metaclass=ABCMeta):
def __getitem__(self, key: T) -> T_co: pass
@overload
def get(self, k: T) -> Optional[T_co]: pass
@overload
def get(self, k: T, default: Union[T_co, V]) -> Union[T_co, V]: pass
def values(self) -> Iterable[T_co]: pass # Approximate return type
def items(self) -> Iterable[Tuple[T, T_co]]: pass # Approximate return type
def __len__(self) -> int: ...
def __contains__(self, arg: object) -> int: pass
class MutableMapping(Mapping[T, U], metaclass=ABCMeta):
def __setitem__(self, k: T, v: U) -> None: pass
class SupportsInt(Protocol):
def __int__(self) -> int: pass
class SupportsFloat(Protocol):
def __float__(self) -> float: pass
def runtime_checkable(cls: T) -> T:
return cls
class ContextManager(Generic[T]):
def __enter__(self) -> T: pass
# Use Any because not all the precise types are in the fixtures.
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> Any: pass
TYPE_CHECKING = 1
# Fallback type for all typed dicts (does not exist at runtime).
class _TypedDict(Mapping[str, object]):
# Needed to make this class non-abstract. It is explicitly declared abstract in
# typeshed, but we don't want to import abc here, as it would slow down the tests.
def __iter__(self) -> Iterator[str]: ...
def copy(self: T) -> T: ...
# Using NoReturn so that only calls using the plugin hook can go through.
def setdefault(self, k: NoReturn, default: object) -> object: ...
# Mypy expects that 'default' has a type variable type.
def pop(self, k: NoReturn, default: T = ...) -> object: ...
def update(self: T, __m: T) -> None: ...
def __delitem__(self, k: NoReturn) -> None: ...