Skip to content

Commit

Permalink
Sync typeshed (#13386)
Browse files Browse the repository at this point in the history
Source commit:
python/typeshed@a92da58

Co-authored-by: Alex Waygood <[email protected]>
  • Loading branch information
jhance and AlexWaygood authored Aug 19, 2022
1 parent 23146c4 commit bf143d9
Show file tree
Hide file tree
Showing 82 changed files with 922 additions and 720 deletions.
3 changes: 2 additions & 1 deletion mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(self, name, covariant: bool = ..., contravariant: bool = ...) -> No
class ParamSpec:
def __init__(self, name: str) -> None: ...
AnyStr = TypeVar("AnyStr", str, bytes)
_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_K = TypeVar("_K")
Expand All @@ -64,7 +65,7 @@ def __init__(self, name: str) -> None: ...
class Coroutine(Generic[_T_co, _S, _R]): ...
class Iterable(Generic[_T_co]): ...
class Mapping(Generic[_K, _V]): ...
class Match(Generic[_T]): ...
class Match(Generic[AnyStr]): ...
class Sequence(Iterable[_T_co]): ...
class Tuple(Sequence[_T_co]): ...
def overload(func: _T) -> _T: ...
Expand Down
4 changes: 0 additions & 4 deletions mypy/typeshed/stdlib/_compression.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ class DecompressReader(RawIOBase):
trailing_error: type[Exception] | tuple[type[Exception], ...] = ...,
**decomp_args: Any,
) -> None: ...
def readable(self) -> bool: ...
def close(self) -> None: ...
def seekable(self) -> bool: ...
def readinto(self, b: WriteableBuffer) -> int: ...
def read(self, size: int = ...) -> bytes: ...
def seek(self, offset: int, whence: int = ...) -> int: ...
def tell(self) -> int: ...
9 changes: 5 additions & 4 deletions mypy/typeshed/stdlib/_decimal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class Decimal:
def from_float(cls: type[Self], __f: float) -> Self: ...
def __bool__(self) -> bool: ...
def compare(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
def __hash__(self) -> int: ...
def as_tuple(self) -> DecimalTuple: ...
def as_integer_ratio(self) -> tuple[int, int]: ...
def to_eng_string(self, context: Context | None = ...) -> str: ...
Expand Down Expand Up @@ -179,6 +178,11 @@ class _ContextManager:
_TrapType: TypeAlias = type[DecimalException]

class Context:
# TODO: Context doesn't allow you to delete *any* attributes from instances of the class at runtime,
# even settable attributes like `prec` and `rounding`,
# but that's inexpressable in the stub.
# Type checkers either ignore it or misinterpret it
# if you add a `def __delattr__(self, __name: str) -> NoReturn` method to the stub
prec: int
rounding: str
Emin: int
Expand All @@ -199,9 +203,6 @@ class Context:
traps: None | dict[_TrapType, bool] | Container[_TrapType] = ...,
_ignored_flags: list[_TrapType] | None = ...,
) -> None: ...
# __setattr__() only allows to set a specific set of attributes,
# already defined above.
def __delattr__(self, __name: str) -> None: ...
def __reduce__(self: Self) -> tuple[type[Self], tuple[Any, ...]]: ...
def clear_flags(self) -> None: ...
def clear_traps(self) -> None: ...
Expand Down
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/_dummy_thread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def stack_size(size: int | None = ...) -> int: ...

class LockType:
locked_status: bool
def __init__(self) -> None: ...
def acquire(self, waitflag: bool | None = ..., timeout: int = ...) -> bool: ...
def __enter__(self, waitflag: bool | None = ..., timeout: int = ...) -> bool: ...
def __exit__(self, typ: type[BaseException] | None, val: BaseException | None, tb: TracebackType | None) -> None: ...
Expand Down
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/_markupbase.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import sys
from typing import Any

class ParserBase:
def __init__(self) -> None: ...
def reset(self) -> None: ...
def getpos(self) -> tuple[int, int]: ...
def unknown_decl(self, data: str) -> None: ...
Expand Down
2 changes: 0 additions & 2 deletions mypy/typeshed/stdlib/_threading_local.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ _LocalDict: TypeAlias = dict[Any, Any]
class _localimpl:
key: str
dicts: dict[int, tuple[ReferenceType[Any], _LocalDict]]
def __init__(self) -> None: ...
def get_dict(self) -> _LocalDict: ...
def create_dict(self) -> _LocalDict: ...

class local:
def __getattribute__(self, name: str) -> Any: ...
def __setattr__(self, name: str, value: Any) -> None: ...
def __delattr__(self, name: str) -> None: ...
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/_weakref.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class ReferenceType(Generic[_T]):
__callback__: Callable[[ReferenceType[_T]], Any]
def __new__(cls: type[Self], o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ...
def __call__(self) -> _T | None: ...
def __hash__(self) -> int: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...

Expand Down
2 changes: 0 additions & 2 deletions mypy/typeshed/stdlib/_weakrefset.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ class WeakSet(MutableSet[_T], Generic[_T]):
@overload
def __init__(self, data: Iterable[_T]) -> None: ...
def add(self, item: _T) -> None: ...
def clear(self) -> None: ...
def discard(self, item: _T) -> None: ...
def copy(self: Self) -> Self: ...
def pop(self) -> _T: ...
def remove(self, item: _T) -> None: ...
def update(self, other: Iterable[_T]) -> None: ...
def __contains__(self, item: object) -> bool: ...
Expand Down
2 changes: 0 additions & 2 deletions mypy/typeshed/stdlib/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class array(MutableSequence[_T], Generic[_T]):
def insert(self, __i: int, __v: _T) -> None: ...
def pop(self, __i: int = ...) -> _T: ...
def remove(self, __v: _T) -> None: ...
def reverse(self) -> None: ...
def tobytes(self) -> bytes: ...
def tofile(self, __f: SupportsWrite[bytes]) -> None: ...
def tolist(self) -> list[_T]: ...
Expand All @@ -56,7 +55,6 @@ class array(MutableSequence[_T], Generic[_T]):
def fromstring(self, __buffer: bytes) -> None: ...
def tostring(self) -> bytes: ...

def __contains__(self, __key: object) -> bool: ...
def __len__(self) -> int: ...
@overload
def __getitem__(self, __i: SupportsIndex) -> _T: ...
Expand Down
14 changes: 9 additions & 5 deletions mypy/typeshed/stdlib/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ from typing import Any, TypeVar, overload
from typing_extensions import Literal

if sys.version_info >= (3, 8):
class Num(Constant):
class _ABC(type):
if sys.version_info >= (3, 9):
def __init__(cls, *args: object) -> None: ...

class Num(Constant, metaclass=_ABC):
value: complex

class Str(Constant):
class Str(Constant, metaclass=_ABC):
value: str
# Aliases for value, for backwards compatibility
s: str

class Bytes(Constant):
class Bytes(Constant, metaclass=_ABC):
value: bytes
# Aliases for value, for backwards compatibility
s: bytes

class NameConstant(Constant): ...
class Ellipsis(Constant): ...
class NameConstant(Constant, metaclass=_ABC): ...
class Ellipsis(Constant, metaclass=_ABC): ...

if sys.version_info >= (3, 9):
class slice(AST): ...
Expand Down
7 changes: 0 additions & 7 deletions mypy/typeshed/stdlib/asynchat.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncore
import socket
from abc import abstractmethod

class simple_producer:
Expand All @@ -9,20 +8,14 @@ class simple_producer:
class async_chat(asyncore.dispatcher):
ac_in_buffer_size: int
ac_out_buffer_size: int
def __init__(self, sock: socket.socket | None = ..., map: asyncore._MapType | None = ...) -> None: ...
@abstractmethod
def collect_incoming_data(self, data: bytes) -> None: ...
@abstractmethod
def found_terminator(self) -> None: ...
def set_terminator(self, term: bytes | int | None) -> None: ...
def get_terminator(self) -> bytes | int | None: ...
def handle_read(self) -> None: ...
def handle_write(self) -> None: ...
def handle_close(self) -> None: ...
def push(self, data: bytes) -> None: ...
def push_with_producer(self, producer: simple_producer) -> None: ...
def readable(self) -> bool: ...
def writable(self) -> bool: ...
def close_when_done(self) -> None: ...
def initiate_send(self) -> None: ...
def discard_buffers(self) -> None: ...
14 changes: 1 addition & 13 deletions mypy/typeshed/stdlib/asyncio/base_subprocess.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,10 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
bufsize: int,
**kwargs: Any,
) -> None: ... # undocumented
def set_protocol(self, protocol: protocols.BaseProtocol) -> None: ...
def get_protocol(self) -> protocols.BaseProtocol: ...
def is_closing(self) -> bool: ...
def close(self) -> None: ...
def get_pid(self) -> int | None: ... # type: ignore[override]
def get_returncode(self) -> int | None: ...
def get_pipe_transport(self, fd: int) -> _File: ... # type: ignore[override]
def _check_proc(self) -> None: ... # undocumented
def send_signal(self, signal: int) -> None: ... # type: ignore[override]
def terminate(self) -> None: ...
def kill(self) -> None: ...
async def _connect_pipes(self, waiter: futures.Future[Any] | None) -> None: ... # undocumented
def _call(self, cb: Callable[..., object], *data: Any) -> None: ... # undocumented
def _pipe_connection_lost(self, fd: int, exc: BaseException | None) -> None: ... # undocumented
Expand All @@ -66,10 +59,5 @@ class BaseSubprocessTransport(transports.SubprocessTransport):

class WriteSubprocessPipeProto(protocols.BaseProtocol): # undocumented
def __init__(self, proc: BaseSubprocessTransport, fd: int) -> None: ...
def connection_made(self, transport: transports.BaseTransport) -> None: ...
def connection_lost(self, exc: BaseException | None) -> None: ...
def pause_writing(self) -> None: ...
def resume_writing(self) -> None: ...

class ReadSubprocessPipeProto(WriteSubprocessPipeProto, protocols.Protocol): # undocumented
def data_received(self, data: bytes) -> None: ...
class ReadSubprocessPipeProto(WriteSubprocessPipeProto, protocols.Protocol): ... # undocumented
2 changes: 0 additions & 2 deletions mypy/typeshed/stdlib/asyncio/events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class TimerHandle(Handle):
loop: AbstractEventLoop,
context: Context | None = ...,
) -> None: ...
def __hash__(self) -> int: ...
def when(self) -> float: ...
def __lt__(self, other: TimerHandle) -> bool: ...
def __le__(self, other: TimerHandle) -> bool: ...
Expand Down Expand Up @@ -612,7 +611,6 @@ class AbstractEventLoopPolicy:
def set_child_watcher(self, watcher: AbstractChildWatcher) -> None: ...

class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy, metaclass=ABCMeta):
def __init__(self) -> None: ...
def get_event_loop(self) -> AbstractEventLoop: ...
def set_event_loop(self, loop: AbstractEventLoop | None) -> None: ...
def new_event_loop(self) -> AbstractEventLoop: ...
Expand Down
6 changes: 1 addition & 5 deletions mypy/typeshed/stdlib/asyncio/locks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ class Semaphore(_ContextManagerMixin):
def release(self) -> None: ...
def _wake_up_next(self) -> None: ...

class BoundedSemaphore(Semaphore):
if sys.version_info >= (3, 11):
def __init__(self, value: int = ...) -> None: ...
else:
def __init__(self, value: int = ..., *, loop: AbstractEventLoop | None = ...) -> None: ...
class BoundedSemaphore(Semaphore): ...

if sys.version_info >= (3, 11):
class _BarrierState(enum.Enum): # undocumented
Expand Down
31 changes: 4 additions & 27 deletions mypy/typeshed/stdlib/asyncio/proactor_events.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from collections.abc import Mapping
from socket import socket
from typing import Any, Protocol
from typing import Any, ClassVar, Protocol
from typing_extensions import Literal

from . import base_events, constants, events, futures, streams, transports
Expand Down Expand Up @@ -29,8 +29,6 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin, transports.BaseTr
else:
def __del__(self) -> None: ...

def get_write_buffer_size(self) -> int: ...

class _ProactorReadPipeTransport(_ProactorBasePipeTransport, transports.ReadTransport):
if sys.version_info >= (3, 10):
def __init__(
Expand All @@ -54,33 +52,13 @@ class _ProactorReadPipeTransport(_ProactorBasePipeTransport, transports.ReadTran
server: events.AbstractServer | None = ...,
) -> None: ...

class _ProactorBaseWritePipeTransport(_ProactorBasePipeTransport, transports.WriteTransport):
def __init__(
self,
loop: events.AbstractEventLoop,
sock: socket,
protocol: streams.StreamReaderProtocol,
waiter: futures.Future[Any] | None = ...,
extra: Mapping[Any, Any] | None = ...,
server: events.AbstractServer | None = ...,
) -> None: ...

class _ProactorWritePipeTransport(_ProactorBaseWritePipeTransport):
def __init__(
self,
loop: events.AbstractEventLoop,
sock: socket,
protocol: streams.StreamReaderProtocol,
waiter: futures.Future[Any] | None = ...,
extra: Mapping[Any, Any] | None = ...,
server: events.AbstractServer | None = ...,
) -> None: ...

class _ProactorBaseWritePipeTransport(_ProactorBasePipeTransport, transports.WriteTransport): ...
class _ProactorWritePipeTransport(_ProactorBaseWritePipeTransport): ...
class _ProactorDuplexPipeTransport(_ProactorReadPipeTransport, _ProactorBaseWritePipeTransport, transports.Transport): ...

class _ProactorSocketTransport(_ProactorReadPipeTransport, _ProactorBaseWritePipeTransport, transports.Transport):

_sendfile_compatible: constants._SendfileMode
_sendfile_compatible: ClassVar[constants._SendfileMode]
def __init__(
self,
loop: events.AbstractEventLoop,
Expand All @@ -92,7 +70,6 @@ class _ProactorSocketTransport(_ProactorReadPipeTransport, _ProactorBaseWritePip
) -> None: ...
def _set_extra(self, sock: socket) -> None: ...
def can_write_eof(self) -> Literal[True]: ...
def write_eof(self) -> None: ...

class BaseProactorEventLoop(base_events.BaseEventLoop):
def __init__(self, proactor: Any) -> None: ...
15 changes: 0 additions & 15 deletions mypy/typeshed/stdlib/asyncio/sslproto.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,10 @@ class _SSLProtocolTransport(transports._FlowControlMixin, transports.Transport):
_closed: bool
def __init__(self, loop: events.AbstractEventLoop, ssl_protocol: SSLProtocol) -> None: ...
def get_extra_info(self, name: str, default: Any | None = ...) -> dict[str, Any]: ...
def set_protocol(self, protocol: protocols.BaseProtocol) -> None: ...
def get_protocol(self) -> protocols.BaseProtocol: ...
def is_closing(self) -> bool: ...
def close(self) -> None: ...
def is_reading(self) -> bool: ...
def pause_reading(self) -> None: ...
def resume_reading(self) -> None: ...
def set_write_buffer_limits(self, high: int | None = ..., low: int | None = ...) -> None: ...
def get_write_buffer_size(self) -> int: ...
@property
def _protocol_paused(self) -> bool: ...
def write(self, data: bytes) -> None: ...
def can_write_eof(self) -> Literal[False]: ...
def abort(self) -> None: ...
if sys.version_info >= (3, 11):
def get_write_buffer_limits(self) -> tuple[int, int]: ...
def get_read_buffer_limits(self) -> tuple[int, int]: ...
Expand Down Expand Up @@ -149,10 +139,7 @@ class SSLProtocol(_SSLProtocolBase):

def _set_app_protocol(self, app_protocol: protocols.BaseProtocol) -> None: ...
def _wakeup_waiter(self, exc: BaseException | None = ...) -> None: ...
def connection_made(self, transport: transports.BaseTransport) -> None: ...
def connection_lost(self, exc: BaseException | None) -> None: ...
def pause_writing(self) -> None: ...
def resume_writing(self) -> None: ...
def eof_received(self) -> None: ...
def _get_extra_info(self, name: str, default: Any | None = ...) -> Any: ...
def _start_shutdown(self) -> None: ...
Expand All @@ -167,9 +154,7 @@ class SSLProtocol(_SSLProtocolBase):
def _fatal_error(self, exc: BaseException, message: str = ...) -> None: ...
def _abort(self) -> None: ...
if sys.version_info >= (3, 11):
def buffer_updated(self, nbytes: int) -> None: ...
def get_buffer(self, n: int) -> memoryview: ...
else:
def _finalize(self) -> None: ...
def _process_write_backlog(self) -> None: ...
def data_received(self, data: bytes) -> None: ...
4 changes: 0 additions & 4 deletions mypy/typeshed/stdlib/asyncio/streams.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
client_connected_cb: _ClientConnectedCallback | None = ...,
loop: events.AbstractEventLoop | None = ...,
) -> None: ...
def connection_made(self, transport: transports.BaseTransport) -> None: ...
def connection_lost(self, exc: Exception | None) -> None: ...
def data_received(self, data: bytes) -> None: ...
def eof_received(self) -> bool: ...

class StreamWriter:
def __init__(
Expand Down
3 changes: 0 additions & 3 deletions mypy/typeshed/stdlib/asyncio/subprocess.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ class SubprocessStreamProtocol(streams.FlowControlMixin, protocols.SubprocessPro
stdout: streams.StreamReader | None
stderr: streams.StreamReader | None
def __init__(self, limit: int, loop: events.AbstractEventLoop) -> None: ...
def connection_made(self, transport: transports.BaseTransport) -> None: ...
def pipe_data_received(self, fd: int, data: bytes | str) -> None: ...
def pipe_connection_lost(self, fd: int, exc: Exception | None) -> None: ...
def process_exited(self) -> None: ...

class Process:
stdin: streams.StreamWriter | None
Expand Down
4 changes: 0 additions & 4 deletions mypy/typeshed/stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@ class Task(Future[_T], Generic[_T]):

def get_stack(self, *, limit: int | None = ...) -> list[FrameType]: ...
def print_stack(self, *, limit: int | None = ..., file: TextIO | None = ...) -> None: ...
if sys.version_info >= (3, 9):
def cancel(self, msg: Any | None = ...) -> bool: ...
else:
def cancel(self) -> bool: ...
if sys.version_info >= (3, 11):
def cancelling(self) -> int: ...
def uncancel(self) -> int: ...
Expand Down
3 changes: 0 additions & 3 deletions mypy/typeshed/stdlib/asyncio/transports.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,3 @@ class SubprocessTransport(BaseTransport):

class _FlowControlMixin(Transport):
def __init__(self, extra: Mapping[Any, Any] | None = ..., loop: AbstractEventLoop | None = ...) -> None: ...
def set_write_buffer_limits(self, high: int | None = ..., low: int | None = ...) -> None: ...
def get_write_buffer_size(self) -> int: ...
def get_write_buffer_limits(self) -> tuple[int, int]: ...
Loading

0 comments on commit bf143d9

Please sign in to comment.