Skip to content

Commit

Permalink
Sync typeshed (#11600)
Browse files Browse the repository at this point in the history
  • Loading branch information
JukkaL authored Nov 23, 2021
1 parent ce3975d commit 4996d57
Show file tree
Hide file tree
Showing 73 changed files with 1,093 additions and 752 deletions.
11 changes: 8 additions & 3 deletions mypy/typeshed/stdlib/@python2/__builtin__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class type(object):
def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ...
def __call__(self, *args: Any, **kwds: Any) -> Any: ...
def __subclasses__(self: _TT) -> List[_TT]: ...
# Note: the documentation doesnt specify what the return type is, the standard
# Note: the documentation doesn't specify what the return type is, the standard
# implementation seems to be returning a list.
def mro(self) -> List[type]: ...
def __instancecheck__(self, instance: Any) -> bool: ...
Expand Down Expand Up @@ -850,13 +850,18 @@ def format(__value: object, __format_spec: str = ...) -> str: ... # TODO unicod
@overload
def getattr(__o: Any, name: Text) -> Any: ...

# While technically covered by the last overload, spelling out the types for None and bool
# help mypy out in some tricky situations involving type context (aka bidirectional inference)
# While technically covered by the last overload, spelling out the types for None, bool
# and basic containers help mypy out in some tricky situations involving type context
# (aka bidirectional inference)
@overload
def getattr(__o: Any, name: Text, __default: None) -> Any | None: ...
@overload
def getattr(__o: Any, name: Text, __default: bool) -> Any | bool: ...
@overload
def getattr(__o: object, name: str, __default: list[Any]) -> Any | list[Any]: ...
@overload
def getattr(__o: object, name: str, __default: dict[Any, Any]) -> Any | dict[Any, Any]: ...
@overload
def getattr(__o: Any, name: Text, __default: _T) -> Any | _T: ...
def globals() -> Dict[str, Any]: ...
def hasattr(__obj: Any, __name: Text) -> bool: ...
Expand Down
3 changes: 1 addition & 2 deletions mypy/typeshed/stdlib/@python2/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
# from _ast below when loaded in an unorthodox way by the Dropbox
# internal Bazel integration.
import typing as _typing
from typing import Any, Iterator

from _ast import *
from _ast import AST, Module
from typing import Any, Iterator

def parse(source: str | unicode, filename: str | unicode = ..., mode: str | unicode = ...) -> Module: ...
def copy_location(new_node: AST, old_node: AST) -> AST: ...
Expand Down
11 changes: 8 additions & 3 deletions mypy/typeshed/stdlib/@python2/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class type(object):
def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ...
def __call__(self, *args: Any, **kwds: Any) -> Any: ...
def __subclasses__(self: _TT) -> List[_TT]: ...
# Note: the documentation doesnt specify what the return type is, the standard
# Note: the documentation doesn't specify what the return type is, the standard
# implementation seems to be returning a list.
def mro(self) -> List[type]: ...
def __instancecheck__(self, instance: Any) -> bool: ...
Expand Down Expand Up @@ -850,13 +850,18 @@ def format(__value: object, __format_spec: str = ...) -> str: ... # TODO unicod
@overload
def getattr(__o: Any, name: Text) -> Any: ...

# While technically covered by the last overload, spelling out the types for None and bool
# help mypy out in some tricky situations involving type context (aka bidirectional inference)
# While technically covered by the last overload, spelling out the types for None, bool
# and basic containers help mypy out in some tricky situations involving type context
# (aka bidirectional inference)
@overload
def getattr(__o: Any, name: Text, __default: None) -> Any | None: ...
@overload
def getattr(__o: Any, name: Text, __default: bool) -> Any | bool: ...
@overload
def getattr(__o: object, name: str, __default: list[Any]) -> Any | list[Any]: ...
@overload
def getattr(__o: object, name: str, __default: dict[Any, Any]) -> Any | dict[Any, Any]: ...
@overload
def getattr(__o: Any, name: Text, __default: _T) -> Any | _T: ...
def globals() -> Dict[str, Any]: ...
def hasattr(__obj: Any, __name: Text) -> bool: ...
Expand Down
6 changes: 3 additions & 3 deletions mypy/typeshed/stdlib/@python2/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def POINTER(type: Type[_CT]) -> Type[pointer[_CT]]: ...
# ctypes._Pointer in that it is the base class for all pointer types. Unlike the real _Pointer,
# it can be instantiated directly (to mimic the behavior of the real pointer function).
class pointer(Generic[_CT], _PointerLike, _CData):
_type_: ClassVar[Type[_CT]] = ...
_type_: Type[_CT] = ...
contents: _CT = ...
def __init__(self, arg: _CT = ...) -> None: ...
@overload
Expand Down Expand Up @@ -262,8 +262,8 @@ class BigEndianStructure(Structure): ...
class LittleEndianStructure(Structure): ...

class Array(Generic[_CT], _CData):
_length_: ClassVar[int] = ...
_type_: ClassVar[Type[_CT]] = ...
_length_: int = ...
_type_: Type[_CT] = ...
raw: bytes = ... # Note: only available if _CT == c_char
value: Any = ... # Note: bytes if _CT == c_char, Text if _CT == c_wchar, unavailable otherwise
# TODO These methods cannot be annotated correctly at the moment.
Expand Down
39 changes: 31 additions & 8 deletions mypy/typeshed/stdlib/@python2/logging/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
import threading
from _typeshed import StrPath
from _typeshed import StrPath, SupportsWrite
from time import struct_time
from types import FrameType, TracebackType
from typing import IO, Any, Callable, Dict, List, Mapping, MutableMapping, Optional, Sequence, Text, Tuple, Union, overload
from typing import (
IO,
Any,
Callable,
Dict,
Generic,
List,
Mapping,
MutableMapping,
Optional,
Sequence,
Text,
Tuple,
TypeVar,
Union,
overload,
)

_SysExcInfoType = Union[Tuple[type, BaseException, Optional[TracebackType]], Tuple[None, None, None]]
_ExcInfoType = Union[None, bool, _SysExcInfoType]
Expand Down Expand Up @@ -159,10 +175,12 @@ class LogRecord:
) -> None: ...
def getMessage(self) -> str: ...

class LoggerAdapter:
logger: Logger
_L = TypeVar("_L", Logger, LoggerAdapter[Logger], LoggerAdapter[Any])

class LoggerAdapter(Generic[_L]):
logger: _L
extra: Mapping[str, Any]
def __init__(self, logger: Logger, extra: Mapping[str, Any]) -> None: ...
def __init__(self, logger: _L, extra: Mapping[str, Any]) -> None: ...
def process(self, msg: Any, kwargs: MutableMapping[str, Any]) -> Tuple[Any, MutableMapping[str, Any]]: ...
def debug(
self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., extra: Dict[str, Any] | None = ..., **kwargs: Any
Expand Down Expand Up @@ -227,9 +245,14 @@ def shutdown(handlerList: Sequence[Any] = ...) -> None: ... # handlerList is un
def setLoggerClass(klass: type) -> None: ...
def captureWarnings(capture: bool) -> None: ...

class StreamHandler(Handler):
stream: IO[str] # undocumented
def __init__(self, stream: IO[str] | None = ...) -> None: ...
_StreamT = TypeVar("_StreamT", bound=SupportsWrite[str])

class StreamHandler(Handler, Generic[_StreamT]):
stream: _StreamT # undocumented
@overload
def __init__(self: StreamHandler[IO[str]], stream: None = ...) -> None: ...
@overload
def __init__(self: StreamHandler[_StreamT], stream: _StreamT) -> None: ...

class FileHandler(StreamHandler):
baseFilename: str # undocumented
Expand Down
3 changes: 1 addition & 2 deletions mypy/typeshed/stdlib/@python2/warnings.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from _warnings import warn as warn, warn_explicit as warn_explicit
from types import ModuleType, TracebackType
from typing import List, TextIO, Type, overload
from typing_extensions import Literal

from _warnings import warn as warn, warn_explicit as warn_explicit

def showwarning(
message: Warning | str, category: Type[Warning], filename: str, lineno: int, file: TextIO | None = ..., line: str | None = ...
) -> None: ...
Expand Down
23 changes: 23 additions & 0 deletions mypy/typeshed/stdlib/_collections_abc.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys
from types import MappingProxyType
from typing import (
AbstractSet as Set,
AsyncGenerator as AsyncGenerator,
Expand All @@ -10,6 +12,7 @@ from typing import (
Container as Container,
Coroutine as Coroutine,
Generator as Generator,
Generic,
Hashable as Hashable,
ItemsView as ItemsView,
Iterable as Iterable,
Expand All @@ -23,8 +26,10 @@ from typing import (
Reversible as Reversible,
Sequence as Sequence,
Sized as Sized,
TypeVar,
ValuesView as ValuesView,
)
from typing_extensions import final

__all__ = [
"Awaitable",
Expand Down Expand Up @@ -53,3 +58,21 @@ __all__ = [
"MutableSequence",
"ByteString",
]

_KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers.
_VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.

@final
class dict_keys(KeysView[_KT_co], Generic[_KT_co, _VT_co]): # undocumented
if sys.version_info >= (3, 10):
mapping: MappingProxyType[_KT_co, _VT_co]

@final
class dict_values(ValuesView[_VT_co], Generic[_KT_co, _VT_co]): # undocumented
if sys.version_info >= (3, 10):
mapping: MappingProxyType[_KT_co, _VT_co]

@final
class dict_items(ItemsView[_KT_co, _VT_co], Generic[_KT_co, _VT_co]): # undocumented
if sys.version_info >= (3, 10):
mapping: MappingProxyType[_KT_co, _VT_co]
3 changes: 3 additions & 0 deletions mypy/typeshed/stdlib/_thread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import sys
from threading import Thread
from types import TracebackType
from typing import Any, Callable, NoReturn, Optional, Tuple, Type
from typing_extensions import final

error = RuntimeError

def _count() -> int: ...

_dangling: Any

@final
class LockType:
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
def release(self) -> None: ...
Expand All @@ -29,6 +31,7 @@ TIMEOUT_MAX: float

if sys.version_info >= (3, 8):
def get_native_id() -> int: ... # only available on some platforms
@final
class _ExceptHookArgs(Tuple[Type[BaseException], Optional[BaseException], Optional[TracebackType], Optional[Thread]]):
@property
def exc_type(self) -> Type[BaseException]: ...
Expand Down
4 changes: 3 additions & 1 deletion mypy/typeshed/stdlib/_tkinter.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Any
from typing_extensions import Literal
from typing_extensions import Literal, final

# _tkinter is meant to be only used internally by tkinter, but some tkinter
# functions e.g. return _tkinter.Tcl_Obj objects. Tcl_Obj represents a Tcl
Expand All @@ -14,6 +14,7 @@ from typing_extensions import Literal
# >>> text.tag_add('foo', '1.0', 'end')
# >>> text.tag_ranges('foo')
# (<textindex object: '1.0'>, <textindex object: '2.0'>)
@final
class Tcl_Obj:
string: str # str(tclobj) returns this
typename: str
Expand All @@ -37,6 +38,7 @@ class TclError(Exception): ...
#
# eval always returns str because _tkinter_tkapp_eval_impl in _tkinter.c calls
# Tkapp_UnicodeResult, and it returns a string when it succeeds.
@final
class TkappType:
# Please keep in sync with tkinter.Tk
def call(self, __command: Any, *args: Any) -> Any: ...
Expand Down
5 changes: 5 additions & 0 deletions mypy/typeshed/stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class SupportsLessThan(Protocol):

SupportsLessThanT = TypeVar("SupportsLessThanT", bound=SupportsLessThan) # noqa: Y001

class SupportsGreaterThan(Protocol):
def __gt__(self, __other: Any) -> bool: ...

SupportsGreaterThanT = TypeVar("SupportsGreaterThanT", bound=SupportsGreaterThan) # noqa: Y001

class SupportsDivMod(Protocol[_T_contra, _T_co]):
def __divmod__(self, __other: _T_contra) -> _T_co: ...

Expand Down
3 changes: 3 additions & 0 deletions mypy/typeshed/stdlib/_weakref.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import sys
from typing import Any, Callable, Generic, TypeVar, overload
from typing_extensions import final

if sys.version_info >= (3, 9):
from types import GenericAlias

_C = TypeVar("_C", bound=Callable[..., Any])
_T = TypeVar("_T")

@final
class CallableProxyType(Generic[_C]): # "weakcallableproxy"
def __getattr__(self, attr: str) -> Any: ...

@final
class ProxyType(Generic[_T]): # "weakproxy"
def __getattr__(self, attr: str) -> Any: ...

Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/_winapi.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from typing import Any, NoReturn, Sequence, overload
from typing_extensions import Literal
from typing_extensions import Literal, final

CREATE_NEW_CONSOLE: int
CREATE_NEW_PROCESS_GROUP: int
Expand Down Expand Up @@ -126,7 +126,7 @@ def WriteFile(handle: int, buffer: bytes, overlapped: Literal[True]) -> tuple[Ov
def WriteFile(handle: int, buffer: bytes, overlapped: Literal[False] = ...) -> tuple[int, int]: ...
@overload
def WriteFile(handle: int, buffer: bytes, overlapped: int | bool) -> tuple[Any, int]: ...

@final
class Overlapped:
event: int
def GetOverlappedResult(self, __wait: bool) -> tuple[int, int]: ...
Expand Down
34 changes: 17 additions & 17 deletions mypy/typeshed/stdlib/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class array(MutableSequence[_T], Generic[_T]):
typecode: _TypeCode
itemsize: int
@overload
def __init__(self: array[int], typecode: _IntTypeCode, __initializer: bytes | Iterable[_T] = ...) -> None: ...
def __init__(self: array[int], __typecode: _IntTypeCode, __initializer: bytes | Iterable[_T] = ...) -> None: ...
@overload
def __init__(self: array[float], typecode: _FloatTypeCode, __initializer: bytes | Iterable[_T] = ...) -> None: ...
def __init__(self: array[float], __typecode: _FloatTypeCode, __initializer: bytes | Iterable[_T] = ...) -> None: ...
@overload
def __init__(self: array[str], typecode: _UnicodeTypeCode, __initializer: bytes | Iterable[_T] = ...) -> None: ...
def __init__(self: array[str], __typecode: _UnicodeTypeCode, __initializer: bytes | Iterable[_T] = ...) -> None: ...
@overload
def __init__(self, typecode: str, __initializer: bytes | Iterable[_T] = ...) -> None: ...
def append(self, __v: _T) -> None: ...
Expand Down Expand Up @@ -48,22 +48,22 @@ class array(MutableSequence[_T], Generic[_T]):
def tostring(self) -> bytes: ...
def __len__(self) -> int: ...
@overload
def __getitem__(self, i: int) -> _T: ...
def __getitem__(self, __i: int) -> _T: ...
@overload
def __getitem__(self, s: slice) -> array[_T]: ...
def __getitem__(self, __s: slice) -> array[_T]: ...
@overload # type: ignore # Overrides MutableSequence
def __setitem__(self, i: int, o: _T) -> None: ...
def __setitem__(self, __i: int, __o: _T) -> None: ...
@overload
def __setitem__(self, s: slice, o: array[_T]) -> None: ...
def __delitem__(self, i: int | slice) -> None: ...
def __add__(self, x: array[_T]) -> array[_T]: ...
def __ge__(self, other: array[_T]) -> bool: ...
def __gt__(self, other: array[_T]) -> bool: ...
def __iadd__(self, x: array[_T]) -> array[_T]: ... # type: ignore # Overrides MutableSequence
def __imul__(self, n: int) -> array[_T]: ...
def __le__(self, other: array[_T]) -> bool: ...
def __lt__(self, other: array[_T]) -> bool: ...
def __mul__(self, n: int) -> array[_T]: ...
def __rmul__(self, n: int) -> array[_T]: ...
def __setitem__(self, __s: slice, __o: array[_T]) -> None: ...
def __delitem__(self, __i: int | slice) -> None: ...
def __add__(self, __x: array[_T]) -> array[_T]: ...
def __ge__(self, __other: array[_T]) -> bool: ...
def __gt__(self, __other: array[_T]) -> bool: ...
def __iadd__(self, __x: array[_T]) -> array[_T]: ... # type: ignore # Overrides MutableSequence
def __imul__(self, __n: int) -> array[_T]: ...
def __le__(self, __other: array[_T]) -> bool: ...
def __lt__(self, __other: array[_T]) -> bool: ...
def __mul__(self, __n: int) -> array[_T]: ...
def __rmul__(self, __n: int) -> array[_T]: ...

ArrayType = array
3 changes: 1 addition & 2 deletions mypy/typeshed/stdlib/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
# sys.
import sys
import typing as _typing
from _ast import * # type: ignore
from typing import Any, Iterator, TypeVar, overload
from typing_extensions import Literal

from _ast import * # type: ignore

if sys.version_info >= (3, 8):
class Num(Constant):
value: complex
Expand Down
5 changes: 3 additions & 2 deletions mypy/typeshed/stdlib/asyncio/base_subprocess.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
from typing import IO, Any, Callable, Deque, Optional, Sequence, Tuple, Union
from collections import deque
from typing import IO, Any, Callable, Optional, Sequence, Tuple, Union

from . import events, futures, protocols, transports

Expand All @@ -14,7 +15,7 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
_pid: int | None # undocumented
_returncode: int | None # undocumented
_exit_waiters: list[futures.Future[Any]] # undocumented
_pending_calls: Deque[tuple[Callable[..., Any], Tuple[Any, ...]]] # undocumented
_pending_calls: deque[tuple[Callable[..., Any], Tuple[Any, ...]]] # undocumented
_pipes: dict[int, _File] # undocumented
_finished: bool # undocumented
def __init__(
Expand Down
Loading

0 comments on commit 4996d57

Please sign in to comment.