diff --git a/builtins/2.7/_functools.pyi b/builtins/2.7/_functools.pyi index ef59af0882c5..d6245db2614e 100644 --- a/builtins/2.7/_functools.pyi +++ b/builtins/2.7/_functools.pyi @@ -1,14 +1,19 @@ """Stub file for the '_functools' module.""" -from typing import Any, Callable, Iterator, Optional, TypeVar, Tuple +from typing import Any, Callable, Dict, Iterator, Optional, TypeVar, Tuple, overload _T = TypeVar("_T") + +@overload +def reduce(function: Callable[[_T, _T], _T], + sequence: Iterator[_T]) -> _T: ... +@overload def reduce(function: Callable[[_T, _T], _T], - sequence: Iterator[_T], initial=Optional[_T]) -> _T: ... + sequence: Iterator[_T], initial: _T) -> _T: ... class partial(object): func = ... # type: Callable[..., Any] - args = ... # type: Tuple[Any] + args = ... # type: Tuple[Any, ...] keywords = ... # type: Dict[str, Any] - def __init__(self, func: Callable[..., Any], *args, **kwargs) -> None: ... - def __call__(self, *args, **kwargs) -> Any: ... + def __init__(self, func: Callable[..., Any], *args: Any, **kwargs: Any) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... diff --git a/builtins/2.7/_random.pyi b/builtins/2.7/_random.pyi index b8cef226e10c..72acbdef5586 100644 --- a/builtins/2.7/_random.pyi +++ b/builtins/2.7/_random.pyi @@ -1,9 +1,13 @@ -from typing import Optional, Union, Any +from typing import Tuple + +# Actually Tuple[(int,) * 625] +_State = Tuple[int, ...] class Random(object): - def __init__(self, seed: Optional[Union[int, Any]] = ..., object = ...) -> None: ... - def getstate(self) -> tuple: ... - def setstate(self, state: tuple) -> None: ... + def __init__(self, seed: object = None) -> None: ... + def seed(self, x: object = None) -> None: ... + def getstate(self) -> _State: ... + def setstate(self, state: _State) -> None: ... def random(self) -> float: ... def getrandbits(self, k: int) -> int: ... def jumpahead(self, i: int) -> None: ... diff --git a/builtins/2.7/_warnings.pyi b/builtins/2.7/_warnings.pyi index 99b86440793d..0b24966ca71d 100644 --- a/builtins/2.7/_warnings.pyi +++ b/builtins/2.7/_warnings.pyi @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, List default_action = ... # type: str filters = ... # type: List[tuple] diff --git a/builtins/2.7/array.pyi b/builtins/2.7/array.pyi index baaa50e136e6..3ff408158d45 100644 --- a/builtins/2.7/array.pyi +++ b/builtins/2.7/array.pyi @@ -1,7 +1,7 @@ """Stub file for the 'array' module.""" from typing import (Any, Generic, IO, Iterable, Sequence, TypeVar, - Union, overload, Iterator, Tuple, BinaryIO) + Union, overload, Iterator, Tuple, BinaryIO, List) T = TypeVar('T') diff --git a/builtins/2.7/builtins.pyi b/builtins/2.7/builtins.pyi index e28f28b9979b..7c5280c2e9a1 100644 --- a/builtins/2.7/builtins.pyi +++ b/builtins/2.7/builtins.pyi @@ -1,7 +1,7 @@ # Stubs for builtins (Python 2.7) from typing import ( - Optional, TypeVar, Iterator, Iterable, overload, + TypeVar, Iterator, Iterable, overload, Sequence, Mapping, Tuple, List, Any, Dict, Callable, Generic, Set, AbstractSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs, SupportsRound, IO, BinaryIO, Union, AnyStr, MutableSequence, MutableMapping, @@ -496,6 +496,7 @@ class list(MutableSequence[_T], Reversible[_T], Generic[_T]): def __delitem__(self, i: Union[int, slice]) -> None: ... def __delslice(self, start: int, stop: int) -> None: ... def __add__(self, x: List[_T]) -> List[_T]: ... + def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... def __contains__(self, o: object) -> bool: ... diff --git a/builtins/2.7/cPickle.pyi b/builtins/2.7/cPickle.pyi index b55f968530c7..acfcdf4a7883 100644 --- a/builtins/2.7/cPickle.pyi +++ b/builtins/2.7/cPickle.pyi @@ -1,4 +1,4 @@ -from typing import Any, IO +from typing import Any, IO, List HIGHEST_PROTOCOL = ... # type: int compatible_formats = ... # type: List[str] diff --git a/builtins/2.7/cStringIO.pyi b/builtins/2.7/cStringIO.pyi index 418b3fd2ecf6..e5bf4653d1f0 100644 --- a/builtins/2.7/cStringIO.pyi +++ b/builtins/2.7/cStringIO.pyi @@ -1,38 +1,50 @@ # Stubs for cStringIO (Python 2.7) # See https://docs.python.org/2/library/stringio.html -from typing import IO, List, Iterable, Iterator, Any, Union +from typing import overload, IO, List, Iterable, Iterator, Optional, Union +from types import TracebackType -class StringIO(IO[str]): - softspace = ... # type: int +# TODO the typing.IO[] generics should be split into input and output. - def __init__(self, s: str = None) -> None: ... +class InputType(IO[str], Iterator[str]): def getvalue(self) -> str: ... def close(self) -> None: ... @property def closed(self) -> bool: ... - def fileno(self) -> int: ... def flush(self) -> None: ... def isatty(self) -> bool: ... def read(self, size: int = -1) -> str: ... - def readable(self) -> bool: ... def readline(self, size: int = -1) -> str: ... def readlines(self, hint: int = -1) -> List[str]: ... def seek(self, offset: int, whence: int = ...) -> None: ... - def seekable(self) -> bool: ... def tell(self) -> int: ... - def truncate(self, size: int = None) -> int: - raise IOError() - def writable(self) -> bool: ... - def __next__(self) -> str: ... - def __enter__(self) -> Any: ... - def __exit__(self, exc_type: type, exc_val: Any, exc_tb: Any) -> Any: ... - # The C extension actually returns an "InputType". - def __iter__(self) -> Iterator[str]: ... - # only StringO: + def truncate(self, size: int = ...) -> Optional[int]: ... + def __iter__(self) -> 'InputType': ... + def next(self) -> str: ... + def reset(self) -> None: ... + +class OutputType(IO[str], Iterator[str]): + @property + def softspace(self) -> int: ... + def getvalue(self) -> str: ... + def close(self) -> None: ... + @property + def closed(self) -> bool: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def read(self, size: int = -1) -> str: ... + def readline(self, size: int = -1) -> str: ... + def readlines(self, hint: int = -1) -> List[str]: ... + def seek(self, offset: int, whence: int = ...) -> None: ... + def tell(self) -> int: ... + def truncate(self, size: int = ...) -> Optional[int]: ... + def __iter__(self) -> 'OutputType': ... + def next(self) -> str: ... def reset(self) -> None: ... def write(self, b: Union[str, unicode]) -> None: ... def writelines(self, lines: Iterable[Union[str, unicode]]) -> None: ... -InputType = StringIO -OutputType = StringIO +@overload +def StringIO() -> OutputType: ... +@overload +def StringIO(s: str) -> InputType: ... diff --git a/builtins/2.7/select.pyi b/builtins/2.7/select.pyi index ba6e9afbb204..53311440599e 100644 --- a/builtins/2.7/select.pyi +++ b/builtins/2.7/select.pyi @@ -1,6 +1,6 @@ """Stubs for the 'select' module.""" -from typing import Any, Optional, Tuple, Iterable +from typing import Any, Optional, Tuple, Iterable, List EPOLLERR = ... # type: int EPOLLET = ... # type: int diff --git a/builtins/2.7/signal.pyi b/builtins/2.7/signal.pyi index 3f9cdc23a9b1..af654b8371bb 100644 --- a/builtins/2.7/signal.pyi +++ b/builtins/2.7/signal.pyi @@ -1,10 +1,11 @@ from typing import Callable, Any, Tuple, Union +from types import FrameType -SIG_DFL = ... # type: long -SIG_IGN = ... # type: long -ITIMER_REAL = ... # type: long -ITIMER_VIRTUAL = ... # type: long -ITIMER_PROF = ... # type: long +SIG_DFL = ... # type: int +SIG_IGN = ... # type: int +ITIMER_REAL = ... # type: int +ITIMER_VIRTUAL = ... # type: int +ITIMER_PROF = ... # type: int SIGABRT = ... # type: int SIGALRM = ... # type: int @@ -43,24 +44,19 @@ SIGXCPU = ... # type: int SIGXFSZ = ... # type: int NSIG = ... # type: int -# Python 3 only: -CTRL_C_EVENT = 0 -CTRL_BREAK_EVENT = 0 -GSIG = 0 - class ItimerError(IOError): ... -_HANDLER = Union[Callable[[int, Any], Any], int, None] +_HANDLER = Union[Callable[[int, FrameType], None], int, None] def alarm(time: int) -> int: ... def getsignal(signalnum: int) -> _HANDLER: ... def pause() -> None: ... def setitimer(which: int, seconds: float, interval: float = None) -> Tuple[float, float]: ... def getitimer(which: int) -> Tuple[float, float]: ... -def set_wakeup_fd(fd: int) -> long: ... +def set_wakeup_fd(fd: int) -> int: ... def siginterrupt(signalnum: int, flag: bool) -> None: raise RuntimeError() -def signal(signalnum: int, handler: _HANDLER) -> None: +def signal(signalnum: int, handler: _HANDLER) -> _HANDLER: raise RuntimeError() -def default_int_handler(*args, **kwargs) -> Any: +def default_int_handler(signum: int, frame: FrameType) -> None: raise KeyboardInterrupt() diff --git a/builtins/2.7/sys.pyi b/builtins/2.7/sys.pyi index 1e955a80a2b9..40b064b00440 100644 --- a/builtins/2.7/sys.pyi +++ b/builtins/2.7/sys.pyi @@ -1,8 +1,9 @@ """Stubs for the 'sys' module.""" from typing import ( - IO, Union, List, Sequence, Any, Dict, Tuple, BinaryIO, overload + IO, Union, List, Sequence, Any, Dict, Tuple, BinaryIO, Optional, Callable, overload ) +from types import FrameType, ModuleType, TracebackType class _flags: bytes_warning = ... # type: int @@ -42,10 +43,10 @@ class _version_info(Tuple[int, int, int, str, int]): releaselevel = '' serial = 0 -_mercurial = ... # type: tuple +_mercurial = ... # type: Tuple[str, str, str] api_version = ... # type: int argv = ... # type: List[str] -builtin_module_names = ... # type: List[str] +builtin_module_names = ... # type: Tuple[str, ...] byteorder = ... # type: str copyright = ... # type: str dont_write_bytecode = ... # type: bool @@ -58,19 +59,33 @@ long_info = ... # type: object maxint = ... # type: int maxsize = ... # type: int maxunicode = ... # type: int -modules = ... # type: Dict[str, module] +modules = ... # type: Dict[str, ModuleType] path = ... # type: List[str] platform = ... # type: str prefix = ... # type: str py3kwarning = ... # type: bool +__stderr__ = ... # type: IO[str] +__stdin__ = ... # type: IO[str] +__stdout__ = ... # type: IO[str] stderr = ... # type: IO[str] stdin = ... # type: IO[str] stdout = ... # type: IO[str] -subversion = ... # type: tuple +subversion = ... # type: Tuple[str, str, str] version = ... # type: str warnoptions = ... # type: object float_info = ... # type: _float_info version_info = ... # type: _version_info +ps1 = '' +ps2 = '' +last_type = ... # type: type +last_value = ... # type: BaseException +last_traceback = ... # type: TracebackType +# TODO precise types +meta_path = ... # type: List[Any] +path_hooks = ... # type: List[Any] +path_importer_cache = ... # type: Dict[str, Any] +displayhook = ... # type: Optional[Callable[[int], None]] +excepthook = ... # type: Optional[Callable[[type, BaseException, TracebackType], None]] class _WindowsVersionType: major = ... # type: Any @@ -83,17 +98,17 @@ class _WindowsVersionType: suite_mask = ... # type: Any product_type = ... # type: Any -def getwindowsversion() -> _WindowsVersionType: ... # TODO return type +def getwindowsversion() -> _WindowsVersionType: ... def _clear_type_cache() -> None: ... -def _current_frames() -> Dict[int, Any]: ... -def _getframe(depth: int = ...) -> Any: ... # TODO: Return FrameObject +def _current_frames() -> Dict[int, FrameType]: ... +def _getframe(depth: int = ...) -> FrameType: ... def call_tracing(fn: Any, args: Any) -> Any: ... -def displayhook(value: int) -> None: ... # value might be None -def excepthook(type_: type, value: BaseException, traceback: Any) -> None: ... # TODO traceback type +def __displayhook__(value: int) -> None: ... +def __excepthook__(type_: type, value: BaseException, traceback: TracebackType) -> None: ... def exc_clear() -> None: raise DeprecationWarning() -def exc_info() -> Tuple[type, Any, Any]: ... # TODO traceback type +def exc_info() -> Tuple[type, BaseException, TracebackType]: ... def exit(arg: int = ...) -> None: raise SystemExit() def getcheckinterval() -> int: ... # deprecated diff --git a/builtins/2.7/unicodedata.pyi b/builtins/2.7/unicodedata.pyi index ab233af3952e..51280ea7534a 100644 --- a/builtins/2.7/unicodedata.pyi +++ b/builtins/2.7/unicodedata.pyi @@ -1,6 +1,6 @@ """Stubs for the 'unicodedata' module.""" -from typing import Any, TypeVar, Union, Optional +from typing import Any, TypeVar, Union ucd_3_2_0 = ... # type: UCD unidata_version = ... # type: str @@ -12,29 +12,29 @@ _default = TypeVar("_default") def bidirectional(unichr: unicode) -> str: ... def category(unichr: unicode) -> str: ... def combining(unichr: unicode) -> int: ... -def decimal(chr: unicode, default=_default) -> Union[int, _default]: ... +def decimal(chr: unicode, default: _default = ...) -> Union[int, _default]: ... def decomposition(unichr: unicode) -> str: ... -def digit(chr: unicode, default=_default) -> Union[int, _default]: ... +def digit(chr: unicode, default: _default = ...) -> Union[int, _default]: ... def east_asian_width(unichr: unicode): str def lookup(name: str): unicode def mirrored(unichr: unicode): int -def name(chr: unicode, default=_default) -> Union[str, _default]: ... +def name(chr: unicode, default: _default = ...) -> Union[str, _default]: ... def normalize(form: str, unistr: unicode) -> unicode: ... -def numeric(chr, default=_default) -> Union[float, _default]: ... +def numeric(chr, default: _default = ...) -> Union[float, _default]: ... class UCD(object): unidata_version = ... # type: str # The methods below are constructed from the same array in C # (unicodedata_functions) and hence identical to the methods above. - def bidirectional(unichr: unicode) -> str: ... - def category(unichr: unicode) -> str: ... - def combining(unichr: unicode) -> int: ... - def decimal(chr: unicode, default=_default) -> Union[int, _default]: ... - def decomposition(unichr: unicode) -> str: ... - def digit(chr: unicode, default=_default) -> Union[int, _default]: ... - def east_asian_width(unichr: unicode): str - def lookup(name: str): unicode - def mirrored(unichr: unicode): int - def name(chr: unicode, default=_default) -> Union[str, _default]: ... - def normalize(form: str, unistr: unicode) -> unicode: ... - def numeric(chr, default=_default) -> Union[float, _default]: ... + def bidirectional(self, unichr: unicode) -> str: ... + def category(self, unichr: unicode) -> str: ... + def combining(self, unichr: unicode) -> int: ... + def decimal(self, chr: unicode, default: _default = ...) -> Union[int, _default]: ... + def decomposition(self, unichr: unicode) -> str: ... + def digit(self, chr: unicode, default: _default = ...) -> Union[int, _default]: ... + def east_asian_width(self, unichr: unicode): str + def lookup(self, name: str): unicode + def mirrored(self, unichr: unicode): int + def name(self, chr: unicode, default: _default = ...) -> Union[str, _default]: ... + def normalize(self, form: str, unistr: unicode) -> unicode: ... + def numeric(self, chr: unicode, default: _default = ...) -> Union[float, _default]: ... diff --git a/builtins/2.7/zipimport.pyi b/builtins/2.7/zipimport.pyi index fd6db61b2835..b972a37f1ab9 100644 --- a/builtins/2.7/zipimport.pyi +++ b/builtins/2.7/zipimport.pyi @@ -1,7 +1,7 @@ """Stub file for the 'zipimport' module.""" from typing import Dict, Optional -from types import CodeType +from types import CodeType, ModuleType class ZipImportError(ImportError): pass @@ -14,12 +14,12 @@ class zipimporter(object): _files = ... # type: Dict[str, tuple] def __init__(self, path: str) -> None: raise ZipImportError - def find_module(self, fullname: str, path: str = ...) -> Optional[zipimporter]: ... - def get_code(self, fullname: str) -> types.CodeType: ... + def find_module(self, fullname: str, path: str = ...) -> Optional['zipimporter']: ... + def get_code(self, fullname: str) -> CodeType: ... def get_data(self, fullname: str) -> str: raise IOError def get_filename(self, fullname: str) -> str: ... def get_source(self, fullname: str) -> str: ... def is_package(self, fullname: str) -> bool: ... - def load_module(self, fullname: str) -> module: ... + def load_module(self, fullname: str) -> ModuleType: ... diff --git a/builtins/2and3/math.pyi b/builtins/2and3/math.pyi index 50cfbda0d77c..44fb75c336fc 100644 --- a/builtins/2and3/math.pyi +++ b/builtins/2and3/math.pyi @@ -3,6 +3,8 @@ from typing import Tuple, Iterable, Optional +import sys + e = ... # type: float pi = ... # type: float @@ -31,7 +33,8 @@ def fsum(iterable: Iterable) -> float: ... def gamma(x: float) -> float: ... def hypot(x: float, y: float) -> float: ... def isinf(x: float) -> bool: ... -def isfinite(x: float) -> bool: ... +if sys.version_info[0] >= 3: + def isfinite(x: float) -> bool: ... def isnan(x: float) -> bool: ... def ldexp(x: float, i: int) -> float: ... def lgamma(x: float) -> float: ... diff --git a/builtins/3/_operator.pyi b/builtins/3.4/_operator.pyi similarity index 100% rename from builtins/3/_operator.pyi rename to builtins/3.4/_operator.pyi diff --git a/builtins/3/_stat.pyi b/builtins/3.4/_stat.pyi similarity index 100% rename from builtins/3/_stat.pyi rename to builtins/3.4/_stat.pyi diff --git a/builtins/3/_tracemalloc.pyi b/builtins/3.4/_tracemalloc.pyi similarity index 100% rename from builtins/3/_tracemalloc.pyi rename to builtins/3.4/_tracemalloc.pyi diff --git a/builtins/3/_codecs.pyi b/builtins/3/_codecs.pyi index b2f7a1a93a10..23fcd8229e97 100644 --- a/builtins/3/_codecs.pyi +++ b/builtins/3/_codecs.pyi @@ -1,6 +1,6 @@ """Stub file for the '_codecs' module.""" -from typing import Any, AnyStr, Callable, Tuple, Optional +from typing import Any, AnyStr, Callable, Tuple, Optional, Dict import codecs diff --git a/builtins/3/_warnings.pyi b/builtins/3/_warnings.pyi index acf046031122..03f1be1de67f 100644 --- a/builtins/3/_warnings.pyi +++ b/builtins/3/_warnings.pyi @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, List _defaultaction = ... # type: str _onceregistry = ... # type: dict diff --git a/stdlib/3/builtins.pyi b/builtins/3/builtins.pyi similarity index 100% rename from stdlib/3/builtins.pyi rename to builtins/3/builtins.pyi diff --git a/builtins/3/signal.pyi b/builtins/3/signal.pyi index 2040482c5c30..f956e05bbbad 100644 --- a/builtins/3/signal.pyi +++ b/builtins/3/signal.pyi @@ -1,12 +1,14 @@ """Stub file for the 'signal' module.""" -from typing import Any, Callable, List, Tuple, Dict, Generic, Union +from typing import Any, Callable, List, Tuple, Dict, Generic, Union, Optional, Iterable, Set +from types import FrameType class ItimerError(IOError): ... ITIMER_PROF = ... # type: int ITIMER_REAL = ... # type: int ITIMER_VIRTUAL = ... # type: int + NSIG = ... # type: int SIGABRT = ... # type: int SIGALRM = ... # type: int @@ -43,51 +45,73 @@ SIGVTALRM = ... # type: int SIGWINCH = ... # type: int SIGXCPU = ... # type: int SIGXFSZ = ... # type: int + SIG_DFL = ... # type: int SIG_IGN = ... # type: int CTRL_C_EVENT = 0 # Windows CTRL_BREAK_EVENT = 0 # Windows +SIG_BLOCK = ... # type: int +SIG_UNBLOCK = ... # type: int +SIG_SETMASK = ... # type: int + +_HANDLER = Union[Callable[[int, FrameType], None], int, None] + +class struct_siginfo(Tuple[int, int, int, int, int, int, int]): + def __init__(self, sequence: Iterable[int]) -> None: ... + @property + def si_signo(self) -> int: ... + @property + def si_code(self) -> int: ... + @property + def si_errno(self) -> int: ... + @property + def si_pid(self) -> int: ... + @property + def si_uid(self) -> int: ... + @property + def si_status(self) -> int: ... + @property + def si_band(self) -> int: ... + def alarm(time: int) -> int: ... -def default_int_handler(*args, **kwargs) -> Any: +def default_int_handler(signum: int, frame: FrameType) -> None: raise KeyboardInterrupt() -def getitimer(which: int) -> tuple: ... +def getitimer(which: int) -> Tuple[float, float]: ... -def getsignal(signalnum: int) -> None: +def getsignal(signalnum: int) -> _HANDLER: raise ValueError() def pause() -> None: ... -def pthread_kill(a: int, b: int) -> None: +def pthread_kill(thread_id: int, signum: int) -> None: raise OSError() -def pthread_sigmask(a: int, b) -> Any: +def pthread_sigmask(how: int, mask: Iterable[int]) -> Set[int]: raise OSError() def set_wakeup_fd(fd: int) -> int: ... -def setitimer(which: int, seconds: float, internval: float = ...) -> Tuple[float, float]: ... +def setitimer(which: int, seconds: float, interval: float = ...) -> Tuple[float, float]: ... -def siginterrupt(signalnum: int, flag: int) -> None: +def siginterrupt(signalnum: int, flag: bool) -> None: raise OSError() -def signal(signalnum: int, handler: Union[int, Callable[[int, Any], None]]) -> Any: +def signal(signalnum: int, handler: _HANDLER) -> _HANDLER: raise OSError() def sigpending() -> Any: raise OSError() -def sigtimedwait(a, b) -> Any: +def sigtimedwait(sigset: Iterable[int], timeout: float) -> Optional[struct_siginfo]: raise OSError() raise ValueError() -def sigwait(a) -> int: +def sigwait(sigset: Iterable[int]) -> int: raise OSError() -def sigwaitinfo(a) -> tuple: +def sigwaitinfo(sigset: Iterable[int]) -> struct_siginfo: raise OSError() - -... # TODO frame object type diff --git a/stdlib/2.7/StringIO.pyi b/stdlib/2.7/StringIO.pyi index 34da578a8dcd..872bb49ae388 100644 --- a/stdlib/2.7/StringIO.pyi +++ b/stdlib/2.7/StringIO.pyi @@ -1,6 +1,6 @@ # Stubs for StringIO (Python 2) -from typing import Any, IO, AnyStr, Iterator, Iterable, Generic +from typing import Any, IO, AnyStr, Iterator, Iterable, Generic, List class StringIO(IO[AnyStr], Generic[AnyStr]): closed = ... # type: bool diff --git a/stdlib/2.7/codecs.pyi b/stdlib/2.7/codecs.pyi index 78d89cfd5418..b09f0d04bfe6 100644 --- a/stdlib/2.7/codecs.pyi +++ b/stdlib/2.7/codecs.pyi @@ -1,165 +1,194 @@ -# Stubs for codecs (Python 2) -# -# NOTE: This dynamically typed stub was automatically generated by stubgen. - -from typing import Any - -BOM_UTF8 = ... # type: Any -BOM_LE = ... # type: Any -BOM_BE = ... # type: Any -BOM_UTF32_LE = ... # type: Any -BOM_UTF32_BE = ... # type: Any -BOM = ... # type: Any -BOM_UTF32 = ... # type: Any -BOM32_LE = ... # type: Any -BOM32_BE = ... # type: Any -BOM64_LE = ... # type: Any -BOM64_BE = ... # type: Any - -class CodecInfo(tuple): - name = ... # type: Any - encode = ... # type: Any - decode = ... # type: Any - incrementalencoder = ... # type: Any - incrementaldecoder = ... # type: Any - streamwriter = ... # type: Any - streamreader = ... # type: Any - def __new__(cls, encode, decode, streamreader=None, streamwriter=None, incrementalencoder=None, incrementaldecoder=None, name=None): ... +# Better codecs stubs hand-written by o11c. +# https://docs.python.org/2/library/codecs.html +from typing import ( + BinaryIO, + Callable, + Iterable, + Iterator, + List, + Tuple, + Union, +) + +from abc import abstractmethod + + +# TODO: this only satisfies the most common interface, where +# str is the raw form and unicode is the cooked form. +# In the long run, both should become template parameters maybe? +# There *are* str->str and unicode->unicode encodings in the standard library. +# And unlike python 3, they are in fairly widespread use. + +_decoded = unicode +_encoded = str + +# TODO: It is not possible to specify these signatures correctly, because +# they have an optional positional or keyword argument for errors=. +_encode_type = Callable[[_decoded], _encoded] # signature of Codec().encode +_decode_type = Callable[[_encoded], _decoded] # signature of Codec().decode +_stream_reader_type = Callable[[BinaryIO], 'StreamReader'] # signature of StreamReader __init__ +_stream_writer_type = Callable[[BinaryIO], 'StreamWriter'] # signature of StreamWriter __init__ +_incremental_encoder_type = Callable[[], 'IncrementalEncoder'] # signature of IncrementalEncoder __init__ +_incremental_decode_type = Callable[[], 'IncrementalDecoder'] # signature of IncrementalDecoder __init__ + + +def encode(obj: _decoded, encoding: str = 'utf-8', errors: str = 'strict') -> _encoded: + ... +def decode(obj: _encoded, encoding: str = 'utf-8', errors: str = 'strict') -> _decoded: + ... + +def lookup(encoding: str) -> 'CodecInfo': + ... +class CodecInfo(Tuple[_encode_type, _decode_type, _stream_reader_type, _stream_writer_type]): + def __init__(self, encode: _encode_type, decode: _decode_type, streamreader: _stream_reader_type = None, streamwriter: _stream_writer_type = None, incrementalencoder: _incremental_encoder_type = None, incrementaldecoder: _incremental_decode_type = None, name: str = None) -> None: + self.encode = encode + self.decode = decode + self.streamreader = streamreader + self.streamwriter = streamwriter + self.incrementalencoder = incrementalencoder + self.incrementaldecoder = incrementaldecoder + self.name = name + +def getencoder(encoding: str) -> _encode_type: + ... +def getdecoder(encoding: str) -> _encode_type: + ... +def getincrementalencoder(encoding: str) -> _incremental_encoder_type: + ... +def getincrementaldecoder(encoding: str) -> _incremental_encoder_type: + ... +def getreader(encoding: str) -> _stream_reader_type: + ... +def getwriter(encoding: str) -> _stream_writer_type: + ... + +def register(search_function: Callable[[str], CodecInfo]) -> None: + ... + +def open(filename: str, mode: str = 'r', encoding: str = None, errors: str = 'strict', buffering: int = 1) -> StreamReaderWriter: + ... + +def EncodedFile(file: BinaryIO, data_encoding: str, file_encoding: str = None, errors = 'strict') -> 'StreamRecoder': + ... + +def iterencode(iterator: Iterable[_decoded], encoding: str, errors: str = 'strict') -> Iterator[_encoded]: + ... +def iterdecode(iterator: Iterable[_encoded], encoding: str, errors: str = 'strict') -> Iterator[_decoded]: + ... + +BOM = b'' +BOM_BE = b'' +BOM_LE = b'' +BOM_UTF8 = b'' +BOM_UTF16 = b'' +BOM_UTF16_BE = b'' +BOM_UTF16_LE = b'' +BOM_UTF32 = b'' +BOM_UTF32_BE = b'' +BOM_UTF32_LE = b'' + +# It is expected that different actions be taken depending on which of the +# three subclasses of `UnicodeError` is actually ...ed. However, the Union +# is still needed for at least one of the cases. +def register_error(name: str, error_handler: Callable[[UnicodeError], Tuple[Union[str, bytes], int]]) -> None: + ... +def lookup_error(name: str) -> Callable[[UnicodeError], Tuple[Union[str, bytes], int]]: + ... + +def strict_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: + ... +def replace_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: + ... +def ignore_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: + ... +def xmlcharrefreplace_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: + ... +def backslashreplace_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: + ... class Codec: - def encode(self, input, errors=''): ... - def decode(self, input, errors=''): ... + # These are sort of @abstractmethod but sort of not. + # The StreamReader and StreamWriter subclasses only implement one. + def encode(self, input: _decoded, errors: str = 'strict') -> Tuple[_encoded, int]: + ... + def decode(self, input: _encoded, errors: str = 'strict') -> Tuple[_decoded, int]: + ... class IncrementalEncoder: - errors = ... # type: Any - buffer = ... # type: Any - def __init__(self, errors=''): ... - def encode(self, input, final=False): ... - def reset(self): ... - def getstate(self): ... - def setstate(self, state): ... - -class BufferedIncrementalEncoder(IncrementalEncoder): - buffer = ... # type: Any - def __init__(self, errors=''): ... - def encode(self, input, final=False): ... - def reset(self): ... - def getstate(self): ... - def setstate(self, state): ... + def __init__(self, errors: str = 'strict') -> None: + self.errors = errors + @abstractmethod + def encode(self, object: _decoded, final: bool = False) -> _encoded: + ... + def reset(self) -> None: + ... + # documentation says int but str is needed for the subclass. + def getstate(self) -> Union[int, _decoded]: + ... + def setstate(self, state: Union[int, _decoded]) -> None: + ... class IncrementalDecoder: - errors = ... # type: Any - def __init__(self, errors=''): ... - def decode(self, input, final=False): ... - def reset(self): ... - def getstate(self): ... - def setstate(self, state): ... + def __init__(self, errors: str = 'strict') -> None: + self.errors = errors + @abstractmethod + def decode(self, object: _encoded, final: bool = False) -> _decoded: + ... + def reset(self) -> None: + ... + def getstate(self) -> Tuple[_encoded, int]: + ... + def setstate(self, state: Tuple[_encoded, int]) -> None: + ... +# These are not documented but used in encodings/*.py implementations. +class BufferedIncrementalEncoder(IncrementalEncoder): + def __init__(self, errors: str = 'strict') -> None: + IncrementalEncoder.__init__(self, errors) + self.buffer = '' + @abstractmethod + def _buffer_encode(self, input: _decoded, errors: str, final: bool) -> _encoded: + ... + def encode(self, input: _decoded, final: bool = False) -> _encoded: + ... class BufferedIncrementalDecoder(IncrementalDecoder): - buffer = ... # type: Any - def __init__(self, errors=''): ... - def decode(self, input, final=False): ... - def reset(self): ... - def getstate(self): ... - def setstate(self, state): ... + def __init__(self, errors: str = 'strict') -> None: + IncrementalDecoder.__init__(self, errors) + self.buffer = b'' + @abstractmethod + def _buffer_decode(self, input: _encoded, errors: str, final: bool) -> Tuple[_decoded, int]: + ... + def decode(self, object: _encoded, final: bool = False) -> _decoded: + ... +# TODO: it is not possible to specify the requirement that all other +# attributes and methods are passed-through from the stream. class StreamWriter(Codec): - stream = ... # type: Any - errors = ... # type: Any - def __init__(self, stream, errors=''): ... - def write(self, object): ... - def writelines(self, list): ... - def reset(self): ... - def seek(self, offset, whence=0): ... - def __getattr__(self, name, getattr=...): ... - def __enter__(self): ... - def __exit__(self, type, value, tb): ... + def __init__(self, stream: BinaryIO, errors: str = 'strict') -> None: + self.errors = errors + def write(self, obj: _decoded) -> None: + ... + def writelines(self, list: List[str]) -> None: + ... + def reset(self) -> None: + ... class StreamReader(Codec): - stream = ... # type: Any - errors = ... # type: Any - bytebuffer = ... # type: Any - charbuffer = ... # type: Any - linebuffer = ... # type: Any - def __init__(self, stream, errors=''): ... - def decode(self, input, errors=''): ... - def read(self, size=-1, chars=-1, firstline=False): ... - def readline(self, size=None, keepends=True): ... - def readlines(self, sizehint=None, keepends=True): ... - def reset(self): ... - def seek(self, offset, whence=0): ... - def next(self): ... - def __iter__(self): ... - def __getattr__(self, name, getattr=...): ... - def __enter__(self): ... - def __exit__(self, type, value, tb): ... + def __init__(self, stream: BinaryIO, errors: str = 'strict') -> None: + self.errors = errors + def read(self, size: int = -1, chars: int = -1, firstline: bool = False) -> _decoded: + ... + def readline(self, size: int = -1, keepends: bool = True) -> _decoded: + ... + def readlines(self, sizehint: int = -1, keepends: bool = True) -> List[_decoded]: + ... + def reset(self) -> None: + ... class StreamReaderWriter: - encoding = ... # type: Any - stream = ... # type: Any - reader = ... # type: Any - writer = ... # type: Any - errors = ... # type: Any - def __init__(self, stream, Reader, Writer, errors=''): ... - def read(self, size=-1): ... - def readline(self, size=None): ... - def readlines(self, sizehint=None): ... - def next(self): ... - def __iter__(self): ... - def write(self, data): ... - def writelines(self, list): ... - def reset(self): ... - def seek(self, offset, whence=0): ... - def __getattr__(self, name, getattr=...): ... - def __enter__(self): ... - def __exit__(self, type, value, tb): ... - -class StreamRecoder: - data_encoding = ... # type: Any - file_encoding = ... # type: Any - stream = ... # type: Any - encode = ... # type: Any - decode = ... # type: Any - reader = ... # type: Any - writer = ... # type: Any - errors = ... # type: Any - def __init__(self, stream, encode, decode, Reader, Writer, errors=''): ... - def read(self, size=-1): ... - def readline(self, size=None): ... - def readlines(self, sizehint=None): ... - def next(self): ... - def __iter__(self): ... - def write(self, data): ... - def writelines(self, list): ... - def reset(self): ... - def __getattr__(self, name, getattr=...): ... - def __enter__(self): ... - def __exit__(self, type, value, tb): ... - -def open(filename, mode='', encoding=None, errors='', buffering=1): ... -def EncodedFile(file, data_encoding, file_encoding=None, errors=''): ... -def getencoder(encoding): ... -def getdecoder(encoding): ... -def getincrementalencoder(encoding): ... -def getincrementaldecoder(encoding): ... -def getreader(encoding): ... -def getwriter(encoding): ... -def iterencode(iterator, encoding, errors='', **kwargs): ... -def iterdecode(iterator, encoding, errors='', **kwargs): ... - -strict_errors = ... # type: Any -ignore_errors = ... # type: Any -replace_errors = ... # type: Any -xmlcharrefreplace_errors = ... # type: Any -backslashreplace_errors = ... # type: Any - -# Names in __all__ with no definition: -# BOM_UTF16 -# BOM_UTF16_BE -# BOM_UTF16_LE -# decode -# encode -# lookup -# lookup_error -# register -# register_error + def __init__(self, stream: BinaryIO, Reader: _stream_reader_type, Writer: _stream_writer_type, errors: str = 'strict') -> None: + ... + +class StreamRecoder(BinaryIO): + def __init__(self, stream: BinaryIO, encode: _encode_type, decode: _decode_type, Reader: _stream_reader_type, Writer: _stream_writer_type, errors: str = 'strict') -> None: + ... diff --git a/stdlib/2.7/encodings/__init__.pyi b/stdlib/2.7/encodings/__init__.pyi new file mode 100644 index 000000000000..2ae6c0a9351d --- /dev/null +++ b/stdlib/2.7/encodings/__init__.pyi @@ -0,0 +1,6 @@ +import codecs + +import typing + +def search_function(encoding: str) -> codecs.CodecInfo: + ... diff --git a/stdlib/2.7/encodings/utf_8.pyi b/stdlib/2.7/encodings/utf_8.pyi new file mode 100644 index 000000000000..b10865428d50 --- /dev/null +++ b/stdlib/2.7/encodings/utf_8.pyi @@ -0,0 +1,14 @@ +import codecs + +class IncrementalEncoder(codecs.IncrementalEncoder): + pass +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + pass +class StreamWriter(codecs.StreamWriter): + pass +class StreamReader(codecs.StreamReader): + pass + +def getregentry() -> codecs.CodecInfo: pass +def encode(input: str, errors: str = 'strict') -> bytes: pass +def decode(input: bytes, errors: str = 'strict') -> str: pass diff --git a/stdlib/2.7/functools.pyi b/stdlib/2.7/functools.pyi index 10dd25cafa3a..8f60338c8190 100644 --- a/stdlib/2.7/functools.pyi +++ b/stdlib/2.7/functools.pyi @@ -3,14 +3,14 @@ # NOTE: This dynamically typed stub was automatically generated by stubgen. from abc import ABCMeta, abstractmethod -from typing import Any, Callable, Dict, Sequence +from typing import Any, Callable, Dict, Iterator, Optional, Sequence, Tuple, TypeVar from collections import namedtuple _AnyCallable = Callable[..., Any] -_T = TypeVar("T") +_T = TypeVar("_T") def reduce(function: Callable[[_T], _T], - sequence: Iterator[_T], initial=Optional[_T]) -> _T: ... + sequence: Iterator[_T], initial: Optional[_T] = None) -> _T: ... WRAPPER_ASSIGNMENTS = ... # type: Sequence[str] WRAPPER_UPDATES = ... # type: Sequence[str] @@ -19,11 +19,11 @@ def update_wrapper(wrapper: _AnyCallable, wrapped: _AnyCallable, assigned: Seque updated: Sequence[str] = ...) -> None: ... def wraps(wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequence[str] = ...) -> Callable[[_AnyCallable], _AnyCallable]: ... def total_ordering(cls: type) -> type: ... -def cmp_to_key(mycmp): ... +def cmp_to_key(mycmp: Callable[[_T, _T], bool]) -> Callable[[_T], Any]: ... class partial(object): func = ... # Callable[..., Any] - args = ... # type: Tuple[Any] + args = ... # type: Tuple[Any, ...] keywords = ... # type: Dict[str, Any] - def __init__(self, func: Callable[..., Any], *args, **kwargs) -> None: ... - def __call__(self, *args, **kwargs) -> Any: ... + def __init__(self, func: Callable[..., Any], *args: Any, **kwargs: Any) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... diff --git a/stdlib/2.7/gettext.pyi b/stdlib/2.7/gettext.pyi index 8921be97ff6a..57f00091e8c8 100644 --- a/stdlib/2.7/gettext.pyi +++ b/stdlib/2.7/gettext.pyi @@ -1,6 +1,6 @@ # TODO(MichalPokorny): better types -from typing import Any, IO, Optional, Union +from typing import Any, IO, List, Optional, Union def bindtextdomain(domain: str, localedir: str = None) -> str: ... def bind_textdomain_codeset(domain: str, codeset: str = None) -> str: ... diff --git a/stdlib/2.7/httplib.pyi b/stdlib/2.7/httplib.pyi new file mode 100644 index 000000000000..ca98adb94c4b --- /dev/null +++ b/stdlib/2.7/httplib.pyi @@ -0,0 +1,3 @@ +# Stubs for httplib (incomplete) + +class HTTPException(Exception): ... diff --git a/stdlib/2.7/logging/handlers.pyi b/stdlib/2.7/logging/handlers.pyi index ec179ca4e194..b69f41f4a2bb 100644 --- a/stdlib/2.7/logging/handlers.pyi +++ b/stdlib/2.7/logging/handlers.pyi @@ -51,7 +51,7 @@ class TimedRotatingFileHandler(BaseRotatingHandler): def doRollover(self): ... class WatchedFileHandler(logging.FileHandler): - def __init__(self, filename: str, mode: str = ..., encoding: str = None, delay: int = ...): ... + def __init__(self, filename: str, mode: str = ..., encoding: str = None, delay: int = ...) -> None: ... stream = ... # type: Any def emit(self, record): ... diff --git a/stdlib/2.7/random.pyi b/stdlib/2.7/random.pyi index 1259a217f054..eddf323ea841 100644 --- a/stdlib/2.7/random.pyi +++ b/stdlib/2.7/random.pyi @@ -17,8 +17,8 @@ _T = TypeVar('_T') class Random(_random.Random): def __init__(self, x: object = None) -> None: ... def seed(self, x: object = None) -> None: ... - def getstate(self) -> tuple: ... - def setstate(self, state: tuple) -> None: ... + def getstate(self) -> _random._State: ... + def setstate(self, state: _random._State) -> None: ... def jumpahead(self, n : int) -> None: ... def getrandbits(self, k: int) -> int: ... @overload diff --git a/stdlib/2.7/ssl.pyi b/stdlib/2.7/ssl.pyi new file mode 100644 index 000000000000..c6ca2fa0c170 --- /dev/null +++ b/stdlib/2.7/ssl.pyi @@ -0,0 +1,5 @@ +# Stubs for ssl (incomplete) + +import socket + +class SSLError(socket.error): ... diff --git a/stdlib/2.7/token.pyi b/stdlib/2.7/token.pyi new file mode 100644 index 000000000000..d0c84121ca92 --- /dev/null +++ b/stdlib/2.7/token.pyi @@ -0,0 +1,62 @@ +from typing import Dict + +ENDMARKER = 0 +NAME = 0 +NUMBER = 0 +STRING = 0 +NEWLINE = 0 +INDENT = 0 +DEDENT = 0 +LPAR = 0 +RPAR = 0 +LSQB = 0 +RSQB = 0 +COLON = 0 +COMMA = 0 +SEMI = 0 +PLUS = 0 +MINUS = 0 +STAR = 0 +SLASH = 0 +VBAR = 0 +AMPER = 0 +LESS = 0 +GREATER = 0 +EQUAL = 0 +DOT = 0 +PERCENT = 0 +BACKQUOTE = 0 +LBRACE = 0 +RBRACE = 0 +EQEQUAL = 0 +NOTEQUAL = 0 +LESSEQUAL = 0 +GREATEREQUAL = 0 +TILDE = 0 +CIRCUMFLEX = 0 +LEFTSHIFT = 0 +RIGHTSHIFT = 0 +DOUBLESTAR = 0 +PLUSEQUAL = 0 +MINEQUAL = 0 +STAREQUAL = 0 +SLASHEQUAL = 0 +PERCENTEQUAL = 0 +AMPEREQUAL = 0 +VBAREQUAL = 0 +CIRCUMFLEXEQUAL = 0 +LEFTSHIFTEQUAL = 0 +RIGHTSHIFTEQUAL = 0 +DOUBLESTAREQUAL = 0 +DOUBLESLASH = 0 +DOUBLESLASHEQUAL = 0 +AT = 0 +OP = 0 +ERRORTOKEN = 0 +N_TOKENS = 0 +NT_OFFSET = 0 +tok_name = {} # type: Dict[int, str] + +def ISTERMINAL(x) -> bool: ... +def ISNONTERMINAL(x) -> bool: ... +def ISEOF(x) -> bool: ... diff --git a/stdlib/2.7/types.pyi b/stdlib/2.7/types.pyi index 6baf5d3628e1..a9b5b4475a52 100644 --- a/stdlib/2.7/types.pyi +++ b/stdlib/2.7/types.pyi @@ -1,11 +1,11 @@ # Stubs for types -from typing import Any +from typing import Any, Tuple, Optional class ModuleType: __name__ = ... # type: str __file__ = ... # type: str - def __init__(self, name: str, doc: Any) -> None: ... + def __init__(self, name: str, doc: str) -> None: ... class TracebackType: ... @@ -21,16 +21,16 @@ class ListType: class CodeType: co_argcount = ... # type: int - co_cellvars = ... # type: Tuple[str] + co_cellvars = ... # type: Tuple[str, ...] co_code = ... # type: str - co_consts = ... # type: Tuple[Any] + co_consts = ... # type: Tuple[Any, ...] co_filename = ... # type: Optional[str] co_firstlineno = ... # type: int co_flags = ... # type: int - co_freevars = ... # type: Tuple[str] + co_freevars = ... # type: Tuple[str, ...] co_lnotab = ... # type: str co_name = ... # type: str - co_names = ... # type: Tuple[str] + co_names = ... # type: Tuple[str, ...] co_nlocals= ... # type: int co_stacksize= ... # type: int - co_varnames = ... # type: Tuple[str] + co_varnames = ... # type: Tuple[str, ...] diff --git a/stdlib/2.7/typing.pyi b/stdlib/2.7/typing.pyi index 0b0c78839344..287b970bc709 100644 --- a/stdlib/2.7/typing.pyi +++ b/stdlib/2.7/typing.pyi @@ -200,7 +200,7 @@ class IO(Iterable[AnyStr], Generic[AnyStr]): @abstractmethod def tell(self) -> int: ... @abstractmethod - def truncate(self, size: int = ...) -> int: ... + def truncate(self, size: int = ...) -> Optional[int]: ... @abstractmethod def writable(self) -> bool: ... # TODO buffer objects diff --git a/stdlib/2.7/unittest.pyi b/stdlib/2.7/unittest.pyi new file mode 100644 index 000000000000..f5e3d2ba0baa --- /dev/null +++ b/stdlib/2.7/unittest.pyi @@ -0,0 +1,3 @@ +# Stubs for unittest (2.7, incomplete) + +class TestCase: ... diff --git a/stdlib/2.7/urlparse.pyi b/stdlib/2.7/urlparse.pyi index bf2e7917cef8..832b955b7d7d 100644 --- a/stdlib/2.7/urlparse.pyi +++ b/stdlib/2.7/urlparse.pyi @@ -1,6 +1,6 @@ # Stubs for urlparse (Python 2) -from typing import List, NamedTuple, Tuple +from typing import Dict, List, NamedTuple, Tuple uses_relative = [] # type: List[str] uses_netloc = [] # type: List[str] diff --git a/stdlib/3.3/do-not-remove b/stdlib/3.3/do-not-remove deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/stdlib/3.4/asyncio/__init__.pyi b/stdlib/3.4/asyncio/__init__.pyi index 1f86a7422c4e..e22015e519c5 100644 --- a/stdlib/3.4/asyncio/__init__.pyi +++ b/stdlib/3.4/asyncio/__init__.pyi @@ -1,11 +1,31 @@ """The asyncio package, tracking PEP 3156.""" -from asyncio.futures import Future -from asyncio.tasks import (coroutine, sleep, Task, FIRST_COMPLETED, - FIRST_EXCEPTION, ALL_COMPLETED, wait, wait_for) -from asyncio.events import (AbstractEventLoopPolicy, AbstractEventLoop, - Handle, get_event_loop) -from asyncio.queues import (Queue, PriorityQueue, LifoQueue, JoinableQueue, - QueueFull, QueueEmpty) +from asyncio.futures import ( + Future as Future, +) +from asyncio.tasks import ( + coroutine as coroutine, + sleep as sleep, + Task as Task, + FIRST_COMPLETED as FIRST_COMPLETED, + FIRST_EXCEPTION as FIRST_EXCEPTION, + ALL_COMPLETED as ALL_COMPLETED, + wait as wait, + wait_for as wait_for, +) +from asyncio.events import ( + AbstractEventLoopPolicy as AbstractEventLoopPolicy, + AbstractEventLoop as AbstractEventLoop, + Handle as Handle, + get_event_loop as get_event_loop, +) +from asyncio.queues import ( + Queue as Queue, + PriorityQueue as PriorityQueue, + LifoQueue as LifoQueue, + JoinableQueue as JoinableQueue, + QueueFull as QueueFull, + QueueEmpty as QueueEmpty, +) __all__ = (futures.__all__ + tasks.__all__ + diff --git a/stdlib/3/atexit.pyi b/stdlib/3/atexit.pyi deleted file mode 100644 index 13d2602b0dc4..000000000000 --- a/stdlib/3/atexit.pyi +++ /dev/null @@ -1,5 +0,0 @@ -from typing import TypeVar, Any - -_FT = TypeVar('_FT') - -def register(func: _FT, *args: Any, **kargs: Any) -> _FT: ... diff --git a/stdlib/3/collections.pyi b/stdlib/3/collections.pyi index fcf029d4ee7a..ba656b684de1 100644 --- a/stdlib/3/collections.pyi +++ b/stdlib/3/collections.pyi @@ -7,12 +7,19 @@ # TODO UserString # TODO more abstract base classes (interfaces in mypy) +# These are not exported. from typing import ( TypeVar, Iterable, Generic, Iterator, Dict, overload, - Mapping, List, Tuple, Callable, Set, Sequence, Sized, + Mapping, List, Tuple, Callable, Sized, Optional, Union ) -import typing +# These are exported. +# TODO reexport more. +from typing import ( + MutableMapping as MutableMapping, + Sequence as Sequence, + AbstractSet as Set, +) _T = TypeVar('_T') _KT = TypeVar('_KT') @@ -23,9 +30,6 @@ _VT = TypeVar('_VT') namedtuple = object() -MutableMapping = typing.MutableMapping - - class deque(Sized, Iterable[_T], Generic[_T]): maxlen = 0 # type: Optional[int] # TODO readonly def __init__(self, iterable: Iterable[_T] = None, diff --git a/stdlib/3/encodings/utf_8.pyi b/stdlib/3/encodings/utf_8.pyi index 072de63b4dde..b10865428d50 100644 --- a/stdlib/3/encodings/utf_8.pyi +++ b/stdlib/3/encodings/utf_8.pyi @@ -12,4 +12,3 @@ class StreamReader(codecs.StreamReader): def getregentry() -> codecs.CodecInfo: pass def encode(input: str, errors: str = 'strict') -> bytes: pass def decode(input: bytes, errors: str = 'strict') -> str: pass - diff --git a/stdlib/3/platform.pyi b/stdlib/3/platform.pyi index 13d443b8ab8c..3a614400e9c0 100644 --- a/stdlib/3/platform.pyi +++ b/stdlib/3/platform.pyi @@ -1,9 +1,35 @@ -# Stubs for platform +# Stubs for platform (Python 3.5) -# NOTE: These are incomplete! +from typing import Tuple, NamedTuple -from typing import Tuple +from os import devnull as DEV_NULL -def mac_ver(release: str = '', - version_info: Tuple[str, str, str] = ('', '', ''), - machine: str = '') -> Tuple[str, Tuple[str, str, str], str]: ... +def libc_ver(executable: str = ..., lib: str = '', version: str = '', chunksize: int = 16384) -> Tuple[str, str]: ... +def linux_distribution(distname: str = '', version: str = '', id: str = '', supported_dists: Tuple[str, ...] = ..., full_distribution_name: bool = True) -> Tuple[str, str, str]: ... +def dist(distname: str = '', version: str = '', id: str = '', supported_dists: Tuple[str, ...] = ...) -> Tuple[str, str, str]: ... +from os import popen +def win32_ver(release: str = '', version: str = '', csd: str = '', ptype: str = '') -> Tuple[str, str, str, str]: ... +def mac_ver(release: str = '', versioninfo: Tuple[str, str, str] = ..., machine: str = '') -> Tuple[str, Tuple[str, str, str], str]: ... +def java_ver(release: str = '', vendor: str = '', vminfo: Tuple[str, str, str] = ..., osinfo: Tuple[str, str, str] = ...) -> Tuple[str, str, Tuple[str, str, str], Tuple[str, str, str]]: ... +def system_alias(system: str, release: str, version: str) -> Tuple[str, str, str]: ... +def architecture(executable: str = ..., bits: str = '', linkage: str = '') -> Tuple[str, str]: ... + +uname_result = NamedTuple('uname_result', [('system', str), ('node', str), ('release', str), ('version', str), ('machine', str), ('processor', str)]) + +def uname() -> uname_result: ... +def system() -> str: ... +def node() -> str: ... +def release() -> str: ... +def version() -> str: ... +def machine() -> str: ... +def processor() -> str: ... + +def python_implementation() -> str: ... +def python_version() -> str: ... +def python_version_tuple() -> Tuple[str, str, str]: ... +def python_branch() -> str: ... +def python_revision() -> str: ... +def python_build() -> Tuple[str, str]: ... +def python_compiler() -> str: ... + +def platform(aliased: bool = False, terse: bool = False) -> str: ... diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 4b84c1a68611..1a8d96dbfdb6 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -20,15 +20,15 @@ class CodeType: co_stacksize = ... # type: int co_flags = ... # type: int co_code = ... # type: bytes - co_consts = ... # type: Tuple[Any] - co_names = ... # type: Tuple[str] - co_varnames = ... # type: Tuple[str] + co_consts = ... # type: Tuple[Any, ...] + co_names = ... # type: Tuple[str, ...] + co_varnames = ... # type: Tuple[str, ...] co_filename = ... # type: Optional[str] co_name = ... # type: str co_firstlineno = ... # type: int co_lnotab = ... # type: bytes - co_freevars = ... # type: Tuple[str] - co_cellvars = ... # type: Tuple[str] + co_freevars = ... # type: Tuple[str, ...] + co_cellvars = ... # type: Tuple[str, ...] def __init__(self, argcount: int, kwonlyargcount: int, @@ -36,15 +36,15 @@ class CodeType: stacksize: int, flags: int, codestring: bytes, - constants: Sequence[Any], - names: Sequence[str], - varnames: Sequence[str], + constants: Tuple[Any, ...], + names: Tuple[str, ...], + varnames: Tuple[str, ...], filename: str, name: str, firstlineno: int, lnotab: bytes, - freevars: Sequence[str] = (), - cellvars: Sequence[str] = (), + freevars: Tuple[str, ...] = (), + cellvars: Tuple[str, ...] = (), ) -> None: ... class FrameType: diff --git a/third_party/2.7/google/protobuf/internal/enum_type_wrapper.pyi b/third_party/2.7/google/protobuf/internal/enum_type_wrapper.pyi index 64d359dfd654..ced66b89e1e7 100644 --- a/third_party/2.7/google/protobuf/internal/enum_type_wrapper.pyi +++ b/third_party/2.7/google/protobuf/internal/enum_type_wrapper.pyi @@ -1,4 +1,4 @@ -from typing import Any, Tuple +from typing import Any, List, Tuple class EnumTypeWrapper(object): def __init__(self, enum_type: Any) -> None: ... diff --git a/third_party/2.7/requests/packages/urllib3/connection.pyi b/third_party/2.7/requests/packages/urllib3/connection.pyi index d8bd4159f0a3..4daa1ac85c60 100644 --- a/third_party/2.7/requests/packages/urllib3/connection.pyi +++ b/third_party/2.7/requests/packages/urllib3/connection.pyi @@ -1,6 +1,7 @@ # Stubs for requests.packages.urllib3.connection (Python 3.4) from typing import Any +from httplib import HTTPException from . import packages from . import exceptions from . import util @@ -46,3 +47,5 @@ class VerifiedHTTPSConnection(HTTPSConnection): def connect(self): ... UnverifiedHTTPSConnection = ... # type: Any + +class ConnectionError(Exception): pass diff --git a/third_party/2.7/requests/packages/urllib3/connectionpool.pyi b/third_party/2.7/requests/packages/urllib3/connectionpool.pyi index 1bbeb05471b0..57ebe57b4d0f 100644 --- a/third_party/2.7/requests/packages/urllib3/connectionpool.pyi +++ b/third_party/2.7/requests/packages/urllib3/connectionpool.pyi @@ -3,6 +3,7 @@ # NOTE: This dynamically typed stub was automatically generated by stubgen. from typing import Any +from ssl import SSLError as BaseSSLError from . import exceptions from .packages import ssl_match_hostname from . import packages @@ -32,7 +33,6 @@ HTTPConnection = connection.HTTPConnection HTTPSConnection = connection.HTTPSConnection VerifiedHTTPSConnection = connection.VerifiedHTTPSConnection HTTPException = connection.HTTPException -BaseSSLError = connection.BaseSSLError ConnectionError = connection.ConnectionError RequestMethods = request.RequestMethods HTTPResponse = response.HTTPResponse diff --git a/third_party/2.7/requests/packages/urllib3/packages/ssl_match_hostname/__init__.pyi b/third_party/2.7/requests/packages/urllib3/packages/ssl_match_hostname/__init__.pyi new file mode 100644 index 000000000000..05c03dc085b5 --- /dev/null +++ b/third_party/2.7/requests/packages/urllib3/packages/ssl_match_hostname/__init__.pyi @@ -0,0 +1 @@ +class CertificateError(ValueError): pass diff --git a/third_party/2.7/scribe/scribe.pyi b/third_party/2.7/scribe/scribe.pyi index 9447a0d64366..24bf0c16ca42 100644 --- a/third_party/2.7/scribe/scribe.pyi +++ b/third_party/2.7/scribe/scribe.pyi @@ -2,6 +2,8 @@ # # NOTE: This dynamically typed stub was automatically generated by stubgen. +from typing import Any + import fb303.FacebookService from .ttypes import * from thrift.Thrift import TProcessor diff --git a/third_party/2.7/thrift/protocol/TBinaryProtocol.pyi b/third_party/2.7/thrift/protocol/TBinaryProtocol.pyi index 09a98f602464..a75bf88e63fd 100644 --- a/third_party/2.7/thrift/protocol/TBinaryProtocol.pyi +++ b/third_party/2.7/thrift/protocol/TBinaryProtocol.pyi @@ -2,6 +2,8 @@ # # NOTE: This dynamically typed stub was automatically generated by stubgen. +from typing import Any + from .TProtocol import * class TBinaryProtocol(TProtocolBase): diff --git a/third_party/2.7/thrift/protocol/TProtocol.pyi b/third_party/2.7/thrift/protocol/TProtocol.pyi index 0a52f565627f..93e949fda6b1 100644 --- a/third_party/2.7/thrift/protocol/TProtocol.pyi +++ b/third_party/2.7/thrift/protocol/TProtocol.pyi @@ -2,6 +2,8 @@ # # NOTE: This dynamically typed stub was automatically generated by stubgen. +from typing import Any + from thrift.Thrift import * class TProtocolException(TException): diff --git a/third_party/2.7/thrift/transport/TSocket.pyi b/third_party/2.7/thrift/transport/TSocket.pyi index 3e2b793dc302..da9746297ab2 100644 --- a/third_party/2.7/thrift/transport/TSocket.pyi +++ b/third_party/2.7/thrift/transport/TSocket.pyi @@ -2,6 +2,8 @@ # # NOTE: This dynamically typed stub was automatically generated by stubgen. +from typing import Any + from .TTransport import * class TSocketBase(TTransportBase): diff --git a/third_party/3/enum.pyi b/third_party/3/enum.pyi new file mode 120000 index 000000000000..c83cbb9cd8d9 --- /dev/null +++ b/third_party/3/enum.pyi @@ -0,0 +1 @@ +../../stdlib/3.4/enum.pyi \ No newline at end of file