diff --git a/builtins/2.7/__builtin__.pyi b/builtins/2.7/__builtin__.pyi index 3beaeeaf5..b558a03bb 100644 --- a/builtins/2.7/__builtin__.pyi +++ b/builtins/2.7/__builtin__.pyi @@ -806,3 +806,5 @@ def eval(s: str) -> Any: ... def cmp(x: Any, y: Any) -> int: ... def execfile(filename: str, globals: Dict[str, Any] = None, locals: Dict[str, Any] = None) -> None: ... + +class file(BinaryIO): ... diff --git a/stdlib/2.7/types.pyi b/stdlib/2.7/types.pyi index a9b5b4475..3cd3cfbb8 100644 --- a/stdlib/2.7/types.pyi +++ b/stdlib/2.7/types.pyi @@ -1,23 +1,52 @@ # Stubs for types +# Note, all classes "defined" here require special handling. -from typing import Any, Tuple, Optional +from typing import ( + Any, Callable, Dict, Iterable, Iterator, List, Optional, + Tuple, TypeVar, Union, overload, +) -class ModuleType: - __name__ = ... # type: str - __file__ = ... # type: str - def __init__(self, name: str, doc: str) -> None: ... +_T = TypeVar('_T') -class TracebackType: - ... +class NoneType: ... +TypeType = type +ObjectType = object -class FrameType: - ... +IntType = int +LongType = long +FloatType = float +BooleanType = bool +ComplexType = complex +StringType = str +UnicodeType = unicode +StringTypes = (StringType, UnicodeType) +BufferType = buffer +TupleType = tuple +ListType = list +DictType = DictionaryType = dict -class GeneratorType: - ... +class _Cell: + cell_contents = ... # type: Any -class ListType: - ... +class FunctionType: + func_closure = ... # type: Optional[Tuple[_Cell, ...]] + func_code = ... # type: CodeType + func_defaults = ... # type: Optional[Tuple[Any, ...]] + func_dict = ... # type: Dict[str, Any] + func_doc = ... # type: Optional[str] + func_globals = ... # type: Dict[str, Any] + func_name = ... # type: str + __closure__ = func_closure + __code__ = func_code + __defaults__ = func_defaults + __dict__ = func_dict + __doc__ = func_doc + __globals__ = func_globals + __name__ = func_name + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, obj: Optional[object], type: Optional[type]) -> 'UnboundMethodType': ... + +LambdaType = FunctionType class CodeType: co_argcount = ... # type: int @@ -34,3 +63,100 @@ class CodeType: co_nlocals= ... # type: int co_stacksize= ... # type: int co_varnames = ... # type: Tuple[str, ...] + +class GeneratorType: + gi_code = ... # type: CodeType + gi_frame = ... # type: FrameType + gi_running = ... # type: int + def __iter__(self) -> 'GeneratorType': ... + def close(self) -> None: ... + def next(self) -> Any: ... + def send(self, arg: Any) -> Any: ... + @overload + def throw(self, val: BaseException) -> Any: ... + @overload + def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ... + +class ClassType: ... +class UnboundMethodType: + im_class = ... # type: type + im_func = ... # type: FunctionType + im_self = ... # type: Optional[object] + __func__ = im_func + __self__ = im_self + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... +class InstanceType: ... +MethodType = UnboundMethodType + +class BuiltinFunctionType: + __self__ = ... # type: Optional[object] + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... +BuiltinMethodType = BuiltinFunctionType + +class ModuleType: + __doc__ = ... # type: Optional[str] + __file__ = ... # type: Optional[str] + __name__ = ... # type: str + __package__ = ... # type: Optional[str] + __path__ = ... # type: Optional[Iterable[str]] + def __init__(self, name: str, doc: str) -> None: ... +FileType = file +XRangeType = xrange + +class TracebackType: + tb_frame = ... # type: FrameType + tb_lasti = ... # type: int + tb_lineno = ... # type: int + tb_next = ... # type: TracebackType + +class FrameType: + f_back = ... # type: FrameType + f_builtins = ... # type: Dict[str, Any] + f_code = ... # type: CodeType + f_exc_type = ... # type: None + f_exc_value = ... # type: None + f_exc_traceback = ... # type: None + f_globals = ... # type: Dict[str, Any] + f_lasti = ... # type: int + f_lineno = ... # type: int + f_locals = ... # type: Dict[str, Any] + f_restricted = ... # type: bool + f_trace = ... # type: Callable[[], None] + + def clear(self) -> None: pass + +SliceType = slice +class EllipsisType: ... + +class DictProxyType: + # TODO is it possible to have non-string keys? + # no __init__ + def copy(self) -> dict: ... + def get(self, key: str, default: _T = None) -> Union[Any, _T]: ... + def has_key(self, key: str) -> bool: ... + def items(self) -> List[Tuple[str, Any]]: ... + def iteritems(self) -> Iterator[Tuple[str, Any]]: ... + def iterkeys(self) -> Iterator[str]: ... + def itervalues(self) -> Iterator[Any]: ... + def keys(self) -> List[str]: ... + def values(self) -> List[Any]: ... + def __contains__(self, key: str) -> bool: ... + def __getitem__(self, key: str) -> Any: ... + def __iter__(self) -> Iterator[str]: ... + def __len__(self) -> int: ... + +class NotImplementedType: ... + +class GetSetDescriptorType: + __name__ = ... # type: str + __objclass__ = ... # type: type + def __get__(self, obj: Any, type: type = None) -> Any: ... + def __set__(self, obj: Any) -> None: ... + def __delete__(self, obj: Any) -> None: ... +# Same type on Jython, different on CPython and PyPy, unknown on IronPython. +class MemberDescriptorType: + __name__ = ... # type: str + __objclass__ = ... # type: type + def __get__(self, obj: Any, type: type = None) -> Any: ... + def __set__(self, obj: Any) -> None: ... + def __delete__(self, obj: Any) -> None: ... diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 1a8d96dbf..4c53d16e5 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -1,16 +1,26 @@ # Stubs for types +# Note, all classes "defined" here require special handling. -# TODO this is work in progress +# TODO parts of this should be conditional on version -from typing import Any, Callable, Dict, Sequence, Optional, Tuple +from typing import Any, Callable, Dict, Iterator, Optional, Tuple, TypeVar, Union, overload -class ModuleType: - __name__ = ... # type: str - __file__ = ... # type: str - def __init__(self, name: str, doc: Any) -> None: ... +_T = TypeVar('_T') -class MethodType: ... -class BuiltinMethodType: ... +class _Cell: + cell_contents = ... # type: Any + +class FunctionType: + __closure__ = ... # type: Optional[Tuple[_Cell, ...]] + __code__ = ... # type: CodeType + __defaults__ = ... # type: Optional[Tuple[Any, ...]] + __dict__ = ... # type: Dict[str, Any] + __doc__ = ... # type: Optional[str] + __globals__ = ... # type: Dict[str, Any] + __name__ = ... # type: str + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, obj: Optional[object], type: Optional[type]) -> 'MethodType': ... +LambdaType = FunctionType class CodeType: """Create a code object. Not for the faint of heart.""" @@ -47,6 +57,64 @@ class CodeType: cellvars: Tuple[str, ...] = (), ) -> None: ... +class MappingProxyType: + def copy(self) -> dict: ... + def get(self, key: str, default: _T = None) -> Union[Any, _T]: ... + def items(self) -> Iterator[Tuple[str, Any]]: ... + def keys(self) -> Iterator[str]: ... + def values(self) -> Iterator[Any]: ... + def __contains__(self, key: str) -> bool: ... + def __getitem__(self, key: str) -> Any: ... + def __iter__(self) -> Iterator[str]: ... + def __len__(self) -> int: ... +class SimpleNamespace: ... + +class GeneratorType: + gi_code = ... # type: CodeType + gi_frame = ... # type: FrameType + gi_running = ... # type: bool + gi_yieldfrom = ... # type: Optional[GeneratorType] + def __iter__(self) -> 'GeneratorType': ... + def __next__(self) -> Any: ... + def close(self) -> None: ... + def send(self, arg: Any) -> Any: ... + @overload + def throw(self, val: BaseException) -> Any: ... + @overload + def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ... + +class CoroutineType: + cr_await = ... # type: Optional[Any] + cr_code = ... # type: CodeType + cr_frame = ... # type: FrameType + cr_running = ... # type: bool + def close(self) -> None: ... + def send(self, arg: Any) -> Any: ... + @overload + def throw(self, val: BaseException) -> Any: ... + @overload + def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ... + +class MethodType: + __func__ = ... # type: FunctionType + __self__ = ... # type: object + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... +class BuiltinFunctionType: + __self__ = ... # type: Union[object, ModuleType] + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... +BuiltinMethodType = BuiltinFunctionType + +class ModuleType: + __name__ = ... # type: str + __file__ = ... # type: str + def __init__(self, name: str, doc: Any) -> None: ... + +class TracebackType: + tb_frame = ... # type: FrameType + tb_lasti = ... # type: int + tb_lineno = ... # type: int + tb_next = ... # type: TracebackType + class FrameType: f_back = ... # type: FrameType f_builtins = ... # type: Dict[str, Any] @@ -59,8 +127,23 @@ class FrameType: def clear(self) -> None: pass -class TracebackType: - tb_frame = ... # type: FrameType - tb_lasti = ... # type: int - tb_lineno = ... # type: int - tb_next = ... # type: TracebackType +class GetSetDescriptorType: + __name__ = ... # type: str + __objclass__ = ... # type: type + def __get__(self, obj: Any, type: type = None) -> Any: ... + def __set__(self, obj: Any) -> None: ... + def __delete__(self, obj: Any) -> None: ... +class MemberDescriptorType: + __name__ = ... # type: str + __objclass__ = ... # type: type + def __get__(self, obj: Any, type: type = None) -> Any: ... + def __set__(self, obj: Any) -> None: ... + def __delete__(self, obj: Any) -> None: ... + +def new_class(name: str, bases: Tuple[type, ...] = (), kwds: Dict[str, Any] = None, exec_body: Callable[[Dict[str, Any]], None] = None) -> type: ... +def prepare_class(name: str, bases: Tuple[type, ...] = (), kwds: Dict[str, Any] = None) -> Tuple[type, Dict[str, Any], Dict[str, Any]]: ... + +# Actually a different type, but `property` is special and we want that too. +DynamicClassAttribute = property + +def coroutine(f: Callable[..., Any]) -> CoroutineType: ...