From 3a674645a555221ab76c935d71849691f045637c Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sat, 16 Jan 2016 16:52:01 -0500 Subject: [PATCH 1/3] Assorted fixes to stubs --- stdlib/2.7/inspect.pyi | 9 +++++++++ stdlib/2.7/zlib.pyi | 6 +++--- stdlib/3/inspect.pyi | 14 +++++++++++++- stdlib/3/textwrap.pyi | 1 + stdlib/3/threading.pyi | 6 ++++++ 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/stdlib/2.7/inspect.pyi b/stdlib/2.7/inspect.pyi index f59dec6aa..b1cfb9c56 100644 --- a/stdlib/2.7/inspect.pyi +++ b/stdlib/2.7/inspect.pyi @@ -9,3 +9,12 @@ _FrameRecord = Tuple[_Frame, str, int, str, List[str], int] def currentframe() -> _FrameRecord: ... def stack(context: int = ...) -> List[_FrameRecord]: ... + +# namedtuple('ArgSpec', 'args varargs keywords defaults') +class ArgSpec(tuple): + args = ... # type: List[str] + varargs = ... # type: str + keywords = ... # type: str + defaults = ... # type: tuple + +def getargspec(func: object) -> ArgSpec: ... diff --git a/stdlib/2.7/zlib.pyi b/stdlib/2.7/zlib.pyi index 72bfc88c1..d6a2c8cdc 100644 --- a/stdlib/2.7/zlib.pyi +++ b/stdlib/2.7/zlib.pyi @@ -23,14 +23,14 @@ def crc32(data: str, value: int = ...) -> int: ... def decompress(data: str, wbits: int = ..., bufsize: int = ...) -> str: ... class compressobj: - def __init__(level: int = ..., method: int = ..., wbits: int = ..., memlevel: int = ..., + def __init__(self, level: int = ..., method: int = ..., wbits: int = ..., memlevel: int = ..., strategy: int = ...) -> None: ... def copy(self) -> "compressobj": ... def compress(self, data: str) -> str: ... def flush(self) -> None: ... class decompressobj: - def __init__(wbits: int = ...) -> None: ... + def __init__(self, wbits: int = ...) -> None: ... def copy(self) -> "decompressobj": ... - def decompress(self, data: str) -> str: ... + def decompress(self, data: str, max_length: int = ...) -> str: ... def flush(self) -> None: ... diff --git a/stdlib/3/inspect.pyi b/stdlib/3/inspect.pyi index 9286aa04f..710d7f3b4 100644 --- a/stdlib/3/inspect.pyi +++ b/stdlib/3/inspect.pyi @@ -1,6 +1,6 @@ # Stubs for inspect -from typing import Any, Tuple, List, Callable +from typing import Any, Tuple, List, Dict, Callable from types import FrameType _object = object @@ -31,4 +31,16 @@ class ArgSpec(tuple): def getargspec(func: object) -> ArgSpec: ... +# namedtuple('FullArgSpec', 'args varargs varkw defaults kwonlyargs kwonlydefaults annotations') +class FullArgSpec(tuple): + args = ... # type: List[str] + varargs = ... # type: str + varkw = ... # type: str + defaults = ... # type: tuple + kwonlyargs = ... # type: List[str] + kwonlydefaults = ... # type: Dict[str, Any] + annotations = ... # type: Dict[str, Any] + +def getfullargspec(func: object) -> FullArgSpec: ... + def stack() -> List[Tuple[FrameType, str, int, str, List[str], int]]: ... diff --git a/stdlib/3/textwrap.pyi b/stdlib/3/textwrap.pyi index db8b5bf55..f6441042a 100644 --- a/stdlib/3/textwrap.pyi +++ b/stdlib/3/textwrap.pyi @@ -61,6 +61,7 @@ class TextWrapper: def wrap( + text: str = ..., width: int = ..., *, initial_indent: str = ..., diff --git a/stdlib/3/threading.pyi b/stdlib/3/threading.pyi index a3e2597ba..ea4386d2b 100644 --- a/stdlib/3/threading.pyi +++ b/stdlib/3/threading.pyi @@ -23,6 +23,12 @@ class Thread: def isDaemon(self) -> bool: ... def setDaemon(self, daemon: bool) -> None: ... +class local(object): + # TODO: allows arbitrary parameters... + def __getattr__(self, name: str) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... + def __delattr__(self, name: str) -> None: ... + class Event: def is_set(self) -> bool: ... def set(self) -> None: ... From b7b7da1a859c9900411b0f2b75f3dd7856fb052e Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sat, 16 Jan 2016 16:54:47 -0500 Subject: [PATCH 2/3] Stubgen some more stdlib modules. Copy doctest.pyi from 3 to 2.7. --- stdlib/2.7/doctest.pyi | 9 +++++ stdlib/2.7/platform.pyi | 45 +++++++++++++++++++++ stdlib/3/html/__init__.pyi | 0 stdlib/3/html/entities.pyi | 10 +++++ stdlib/3/numbers.pyi | 80 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 144 insertions(+) create mode 100644 stdlib/2.7/doctest.pyi create mode 100644 stdlib/2.7/platform.pyi create mode 100644 stdlib/3/html/__init__.pyi create mode 100644 stdlib/3/html/entities.pyi create mode 100644 stdlib/3/numbers.pyi diff --git a/stdlib/2.7/doctest.pyi b/stdlib/2.7/doctest.pyi new file mode 100644 index 000000000..ab88328c8 --- /dev/null +++ b/stdlib/2.7/doctest.pyi @@ -0,0 +1,9 @@ +# Stubs for doctest + +# NOTE: These are incomplete! + +from typing import Any, Tuple + +# TODO arguments missing +def testmod(m: Any = ..., name: str = ..., globs: Any = ..., + verbose: bool = ...) -> Tuple[int, int]: ... diff --git a/stdlib/2.7/platform.pyi b/stdlib/2.7/platform.pyi new file mode 100644 index 000000000..83c61fa9c --- /dev/null +++ b/stdlib/2.7/platform.pyi @@ -0,0 +1,45 @@ +# Stubs for platform (Python 2) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any + +__copyright__ = ... # type: Any +DEV_NULL = ... # type: Any + +def libc_ver(executable=..., lib='', version='', chunksize=2048): ... +def linux_distribution(distname='', version='', id='', supported_dists=..., full_distribution_name=1): ... +def dist(distname='', version='', id='', supported_dists=...): ... + +class _popen: + tmpfile = ... # type: Any + pipe = ... # type: Any + bufsize = ... # type: Any + mode = ... # type: Any + def __init__(self, cmd, mode='', bufsize=None): ... + def read(self): ... + def readlines(self): ... + def close(self, remove=..., error=...): ... + __del__ = ... # type: Any + +def popen(cmd, mode='', bufsize=None): ... +def win32_ver(release='', version='', csd='', ptype=''): ... +def mac_ver(release='', versioninfo=..., machine=''): ... +def java_ver(release='', vendor='', vminfo=..., osinfo=...): ... +def system_alias(system, release, version): ... +def architecture(executable=..., bits='', linkage=''): ... +def uname(): ... +def system(): ... +def node(): ... +def release(): ... +def version(): ... +def machine(): ... +def processor(): ... +def python_implementation(): ... +def python_version(): ... +def python_version_tuple(): ... +def python_branch(): ... +def python_revision(): ... +def python_build(): ... +def python_compiler(): ... +def platform(aliased=0, terse=0): ... diff --git a/stdlib/3/html/__init__.pyi b/stdlib/3/html/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/stdlib/3/html/entities.pyi b/stdlib/3/html/entities.pyi new file mode 100644 index 000000000..7cc90b450 --- /dev/null +++ b/stdlib/3/html/entities.pyi @@ -0,0 +1,10 @@ +# Stubs for html.entities (Python 3.5) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any + +name2codepoint = ... # type: Any +html5 = ... # type: Any +codepoint2name = ... # type: Any +entitydefs = ... # type: Any diff --git a/stdlib/3/numbers.pyi b/stdlib/3/numbers.pyi new file mode 100644 index 000000000..8bea0b022 --- /dev/null +++ b/stdlib/3/numbers.pyi @@ -0,0 +1,80 @@ +# Stubs for numbers (Python 3.5) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any + +class Number: + __hash__ = ... # type: Any + +class Complex(Number): + def __complex__(self): ... + def __bool__(self): ... + @property + def real(self): ... + @property + def imag(self): ... + def __add__(self, other): ... + def __radd__(self, other): ... + def __neg__(self): ... + def __pos__(self): ... + def __sub__(self, other): ... + def __rsub__(self, other): ... + def __mul__(self, other): ... + def __rmul__(self, other): ... + def __truediv__(self, other): ... + def __rtruediv__(self, other): ... + def __pow__(self, exponent): ... + def __rpow__(self, base): ... + def __abs__(self): ... + def conjugate(self): ... + def __eq__(self, other): ... + +class Real(Complex): + def __float__(self): ... + def __trunc__(self): ... + def __floor__(self): ... + def __ceil__(self): ... + def __round__(self, ndigits=None): ... + def __divmod__(self, other): ... + def __rdivmod__(self, other): ... + def __floordiv__(self, other): ... + def __rfloordiv__(self, other): ... + def __mod__(self, other): ... + def __rmod__(self, other): ... + def __lt__(self, other): ... + def __le__(self, other): ... + def __complex__(self): ... + @property + def real(self): ... + @property + def imag(self): ... + def conjugate(self): ... + +class Rational(Real): + @property + def numerator(self): ... + @property + def denominator(self): ... + def __float__(self): ... + +class Integral(Rational): + def __int__(self): ... + def __index__(self): ... + def __pow__(self, exponent, modulus=None): ... + def __lshift__(self, other): ... + def __rlshift__(self, other): ... + def __rshift__(self, other): ... + def __rrshift__(self, other): ... + def __and__(self, other): ... + def __rand__(self, other): ... + def __xor__(self, other): ... + def __rxor__(self, other): ... + def __or__(self, other): ... + def __ror__(self, other): ... + def __invert__(self): ... + def __float__(self): ... + @property + def numerator(self): ... + @property + def denominator(self): ... From 1626c250874ec154625ea33e8bbef8be73260f6f Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sat, 16 Jan 2016 16:56:25 -0500 Subject: [PATCH 3/3] Add some third_party modules. backports_abc and singledispatch were made with stubgen, certifi was written by hand, and ssl_match_hostname was copied from ssl.pyi. --- third_party/2and3/backports/__init__.pyi | 0 .../2and3/backports/ssl_match_hostname.pyi | 3 +++ third_party/2and3/backports_abc.pyi | 19 +++++++++++++++++++ third_party/2and3/certifi.pyi | 2 ++ third_party/2and3/singledispatch.pyi | 5 +++++ 5 files changed, 29 insertions(+) create mode 100644 third_party/2and3/backports/__init__.pyi create mode 100644 third_party/2and3/backports/ssl_match_hostname.pyi create mode 100644 third_party/2and3/backports_abc.pyi create mode 100644 third_party/2and3/certifi.pyi create mode 100644 third_party/2and3/singledispatch.pyi diff --git a/third_party/2and3/backports/__init__.pyi b/third_party/2and3/backports/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/third_party/2and3/backports/ssl_match_hostname.pyi b/third_party/2and3/backports/ssl_match_hostname.pyi new file mode 100644 index 000000000..c21998013 --- /dev/null +++ b/third_party/2and3/backports/ssl_match_hostname.pyi @@ -0,0 +1,3 @@ +class CertificateError(ValueError): ... + +def match_hostname(cert, hostname): ... diff --git a/third_party/2and3/backports_abc.pyi b/third_party/2and3/backports_abc.pyi new file mode 100644 index 000000000..a82293fa4 --- /dev/null +++ b/third_party/2and3/backports_abc.pyi @@ -0,0 +1,19 @@ +# Stubs for backports_abc (Python 3.5) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any + +def mk_gen(): ... +def mk_awaitable(): ... +def mk_coroutine(): ... + +Generator = ... # type: Any +Awaitable = ... # type: Any +Coroutine = ... # type: Any + +def isawaitable(obj): ... + +PATCHED = ... # type: Any + +def patch(patch_inspect=True): ... diff --git a/third_party/2and3/certifi.pyi b/third_party/2and3/certifi.pyi new file mode 100644 index 000000000..c809e6d49 --- /dev/null +++ b/third_party/2and3/certifi.pyi @@ -0,0 +1,2 @@ +def where() -> str: ... +def old_where() -> str: ... diff --git a/third_party/2and3/singledispatch.pyi b/third_party/2and3/singledispatch.pyi new file mode 100644 index 000000000..dac3ceae8 --- /dev/null +++ b/third_party/2and3/singledispatch.pyi @@ -0,0 +1,5 @@ +# Stubs for singledispatch (Python 3.5) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +def singledispatch(func): ...