Skip to content

Update Unused and __exit__ parameters in stdlib #9519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stdlib/ast.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os
import sys
from _ast import *
from _typeshed import ReadableBuffer
from _typeshed import ReadableBuffer, Unused
from collections.abc import Iterator
from typing import Any, TypeVar, overload
from typing_extensions import Literal

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

class Num(Constant, metaclass=_ABC):
value: int | float | complex
Expand Down
4 changes: 2 additions & 2 deletions stdlib/asyncio/events.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ssl
import sys
from _typeshed import FileDescriptorLike, ReadableBuffer, Self, StrPath, WriteableBuffer
from _typeshed import FileDescriptorLike, ReadableBuffer, Self, StrPath, Unused, WriteableBuffer
from abc import ABCMeta, abstractmethod
from collections.abc import Awaitable, Callable, Coroutine, Generator, Sequence
from contextvars import Context
Expand Down Expand Up @@ -96,7 +96,7 @@ class AbstractServer:
@abstractmethod
def close(self) -> None: ...
async def __aenter__(self: Self) -> Self: ...
async def __aexit__(self, *exc: object) -> None: ...
async def __aexit__(self, *exc: Unused) -> None: ...
@abstractmethod
def get_loop(self) -> AbstractEventLoop: ...
@abstractmethod
Expand Down
6 changes: 3 additions & 3 deletions stdlib/asyncio/locks.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import enum
import sys
from _typeshed import Self
from _typeshed import Self, Unused
from collections import deque
from collections.abc import Callable, Generator
from types import TracebackType
Expand Down Expand Up @@ -31,7 +31,7 @@ else:
class _ContextManager:
def __init__(self, lock: Lock | Semaphore) -> None: ...
def __enter__(self) -> None: ...
def __exit__(self, *args: object) -> None: ...
def __exit__(self, *args: Unused) -> None: ...

class _ContextManagerMixin:
# Apparently this exists to *prohibit* use as a context manager.
Expand Down Expand Up @@ -104,7 +104,7 @@ if sys.version_info >= (3, 11):
class Barrier(_LoopBoundMixin):
def __init__(self, parties: int) -> None: ...
async def __aenter__(self: Self) -> Self: ...
async def __aexit__(self, *args: object) -> None: ...
async def __aexit__(self, *args: Unused) -> None: ...
async def wait(self) -> int: ...
async def abort(self) -> None: ...
async def reset(self) -> None: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/asyncio/runners.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from _typeshed import Self
from _typeshed import Self, Unused
from collections.abc import Callable, Coroutine
from contextvars import Context
from typing import Any, TypeVar
Expand All @@ -18,7 +18,7 @@ if sys.version_info >= (3, 11):
class Runner:
def __init__(self, *, debug: bool | None = ..., loop_factory: Callable[[], AbstractEventLoop] | None = ...) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, exc_type: object, exc_val: object, exc_tb: object) -> None: ...
def __exit__(self, exc_type: Unused, exc_val: Unused, exc_tb: Unused) -> None: ...
def close(self) -> None: ...
def get_loop(self) -> AbstractEventLoop: ...
def run(self, coro: Coroutine[Any, Any, _T], *, context: Context | None = ...) -> _T: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ class function:

__module__: str
# mypy uses `builtins.function.__get__` to represent methods, properties, and getset_descriptors so we type the return as Any.
def __get__(self, obj: object | None, type: type | None = ...) -> Any: ...
def __get__(self, obj: object, type: type | None = ...) -> Any: ...

class list(MutableSequence[_T], Generic[_T]):
@overload
Expand Down
4 changes: 2 additions & 2 deletions stdlib/cProfile.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from _typeshed import Self, StrOrBytesPath
from _typeshed import Self, StrOrBytesPath, Unused
from collections.abc import Callable
from types import CodeType
from typing import Any, TypeVar
Expand Down Expand Up @@ -32,6 +32,6 @@ class Profile:
def runcall(self, __func: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> _T: ...
if sys.version_info >= (3, 8):
def __enter__(self: Self) -> Self: ...
def __exit__(self, *exc_info: object) -> None: ...
def __exit__(self, *exc_info: Unused) -> None: ...

def label(code: str | CodeType) -> _Label: ... # undocumented
3 changes: 2 additions & 1 deletion stdlib/calendar.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import sys
from _typeshed import Unused
from collections.abc import Iterable, Sequence
from time import struct_time
from typing import ClassVar
Expand Down Expand Up @@ -108,7 +109,7 @@ class HTMLCalendar(Calendar):
class different_locale:
def __init__(self, locale: _LocaleType) -> None: ...
def __enter__(self) -> None: ...
def __exit__(self, *args: object) -> None: ...
def __exit__(self, *args: Unused) -> None: ...

class LocaleTextCalendar(TextCalendar):
def __init__(self, firstweekday: int = ..., locale: _LocaleType | None = ...) -> None: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/cgi.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from _typeshed import Self, SupportsGetItem, SupportsItemAccess
from _typeshed import Self, SupportsGetItem, SupportsItemAccess, Unused
from builtins import list as _list, type as _type
from collections.abc import Iterable, Iterator, Mapping
from email.message import Message
Expand Down Expand Up @@ -106,7 +106,7 @@ class FieldStorage:
separator: str = ...,
) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: object) -> None: ...
def __exit__(self, *args: Unused) -> None: ...
def __iter__(self) -> Iterator[str]: ...
def __getitem__(self, key: str) -> Any: ...
def getvalue(self, key: str, default: Any = ...) -> Any: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/concurrent/futures/_base.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import threading
from _typeshed import Self
from _typeshed import Self, Unused
from collections.abc import Callable, Iterable, Iterator, Sequence
from logging import Logger
from types import TracebackType
Expand Down Expand Up @@ -108,4 +108,4 @@ class _AcquireFutures:
futures: Iterable[Future[Any]]
def __init__(self, futures: Iterable[Future[Any]]) -> None: ...
def __enter__(self) -> None: ...
def __exit__(self, *args: object) -> None: ...
def __exit__(self, *args: Unused) -> None: ...
14 changes: 7 additions & 7 deletions stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc
import sys
from _typeshed import FileDescriptorOrPath, Self
from _typeshed import FileDescriptorOrPath, Self, Unused
from abc import abstractmethod
from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Iterator
from types import TracebackType
Expand Down Expand Up @@ -108,7 +108,7 @@ _SupportsCloseT = TypeVar("_SupportsCloseT", bound=_SupportsClose)

class closing(AbstractContextManager[_SupportsCloseT]):
def __init__(self, thing: _SupportsCloseT) -> None: ...
def __exit__(self, *exc_info: object) -> None: ...
def __exit__(self, *exc_info: Unused) -> None: ...

if sys.version_info >= (3, 10):
class _SupportsAclose(Protocol):
Expand All @@ -117,7 +117,7 @@ if sys.version_info >= (3, 10):

class aclosing(AbstractAsyncContextManager[_SupportsAcloseT]):
def __init__(self, thing: _SupportsAcloseT) -> None: ...
async def __aexit__(self, *exc_info: object) -> None: ...
async def __aexit__(self, *exc_info: Unused) -> None: ...

class suppress(AbstractContextManager[None]):
def __init__(self, *exceptions: type[BaseException]) -> None: ...
Expand Down Expand Up @@ -178,9 +178,9 @@ if sys.version_info >= (3, 10):
@overload
def __init__(self: nullcontext[_T], enter_result: _T) -> None: ...
def __enter__(self) -> _T: ...
def __exit__(self, *exctype: object) -> None: ...
def __exit__(self, *exctype: Unused) -> None: ...
async def __aenter__(self) -> _T: ...
async def __aexit__(self, *exctype: object) -> None: ...
async def __aexit__(self, *exctype: Unused) -> None: ...

else:
class nullcontext(AbstractContextManager[_T]):
Expand All @@ -190,7 +190,7 @@ else:
@overload
def __init__(self: nullcontext[_T], enter_result: _T) -> None: ...
def __enter__(self) -> _T: ...
def __exit__(self, *exctype: object) -> None: ...
def __exit__(self, *exctype: Unused) -> None: ...

if sys.version_info >= (3, 11):
_T_fd_or_any_path = TypeVar("_T_fd_or_any_path", bound=FileDescriptorOrPath)
Expand All @@ -199,4 +199,4 @@ if sys.version_info >= (3, 11):
path: _T_fd_or_any_path
def __init__(self, path: _T_fd_or_any_path) -> None: ...
def __enter__(self) -> None: ...
def __exit__(self, *excinfo: object) -> None: ...
def __exit__(self, *excinfo: Unused) -> None: ...
7 changes: 2 additions & 5 deletions stdlib/distutils/util.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import StrPath
from _typeshed import StrPath, Unused
from collections.abc import Callable, Container, Iterable, Mapping
from typing import Any
from typing_extensions import Literal
Expand All @@ -25,10 +25,7 @@ def byte_compile(
) -> None: ...
def rfc822_escape(header: str) -> str: ...
def run_2to3(
files: Iterable[str],
fixer_names: Iterable[str] | None = ...,
options: Mapping[str, Any] | None = ...,
explicit: Container[str] | None = ..., # unused
files: Iterable[str], fixer_names: Iterable[str] | None = ..., options: Mapping[str, Any] | None = ..., explicit: Unused = ...
) -> None: ...
def copydir_run_2to3(
src: StrPath,
Expand Down
4 changes: 2 additions & 2 deletions stdlib/enum.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import types
from _typeshed import Self, SupportsKeysAndGetItem
from _typeshed import Self, SupportsKeysAndGetItem, Unused
from abc import ABCMeta
from builtins import property as _builtins_property
from collections.abc import Iterable, Iterator, Mapping
Expand Down Expand Up @@ -177,7 +177,7 @@ class Enum(metaclass=EnumMeta):
def __new__(cls: type[Self], value: object) -> Self: ...
def __dir__(self) -> list[str]: ...
def __format__(self, format_spec: str) -> str: ...
def __reduce_ex__(self, proto: object) -> tuple[Any, ...]: ...
def __reduce_ex__(self, proto: Unused) -> tuple[Any, ...]: ...

if sys.version_info >= (3, 11):
class ReprEnum(Enum): ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/mmap.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from _typeshed import ReadableBuffer, Self
from _typeshed import ReadableBuffer, Self, Unused
from collections.abc import Iterable, Iterator, Sized
from typing import NoReturn, overload

Expand Down Expand Up @@ -74,7 +74,7 @@ class mmap(Iterable[int], Sized):
# so we claim that there is also an __iter__ to help type checkers.
def __iter__(self) -> Iterator[int]: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: object) -> None: ...
def __exit__(self, *args: Unused) -> None: ...

if sys.version_info >= (3, 8) and sys.platform != "win32":
MADV_NORMAL: int
Expand Down
4 changes: 2 additions & 2 deletions stdlib/multiprocessing/forkserver.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import FileDescriptorLike
from _typeshed import FileDescriptorLike, Unused
from collections.abc import Sequence
from struct import Struct
from typing import Any
Expand All @@ -19,7 +19,7 @@ def main(
alive_r: FileDescriptorLike,
preload: Sequence[str],
main_path: str | None = ...,
sys_path: object | None = ...,
sys_path: Unused = ...,
) -> None: ...
def read_signed(fd: int) -> Any: ...
def write_signed(fd: int, n: int) -> None: ...
Expand Down
8 changes: 3 additions & 5 deletions stdlib/multiprocessing/reduction.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pickle
import sys
from _typeshed import HasFileno, SupportsWrite
from _typeshed import HasFileno, SupportsWrite, Unused
from abc import ABCMeta
from builtins import type as Type # alias to avoid name clash
from collections.abc import Callable
Expand Down Expand Up @@ -54,8 +54,7 @@ else:
ACKNOWLEDGE: Literal[False]

def recvfds(sock: socket, size: int) -> list[int]: ...
# destination_pid is unused
def send_handle(conn: HasFileno, handle: int, destination_pid: object) -> None: ...
def send_handle(conn: HasFileno, handle: int, destination_pid: Unused) -> None: ...
def recv_handle(conn: HasFileno) -> int: ...
def sendfds(sock: socket, fds: list[int]) -> None: ...
def DupFd(fd: int) -> Any: ... # Return type is really hard to get right
Expand Down Expand Up @@ -92,5 +91,4 @@ class AbstractReducer(metaclass=ABCMeta):
sendfds = _sendfds
recvfds = _recvfds
DupFd = _DupFd
# *args are unused
def __init__(self, *args: object) -> None: ...
def __init__(self, *args: Unused) -> None: ...
6 changes: 3 additions & 3 deletions stdlib/multiprocessing/util.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import threading
from _typeshed import Incomplete, ReadableBuffer, SupportsTrunc
from _typeshed import Incomplete, ReadableBuffer, SupportsTrunc, Unused
from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequence
from logging import Logger, _Level as _LoggingLevel
from typing import Any, SupportsInt
Expand Down Expand Up @@ -56,7 +56,7 @@ class Finalize:
) -> None: ...
def __call__(
self,
wr: object = ...,
wr: Unused = ...,
_finalizer_registry: MutableMapping[Incomplete, Incomplete] = ...,
sub_debug: Callable[..., object] = ...,
getpid: Callable[[], int] = ...,
Expand All @@ -70,7 +70,7 @@ class ForkAwareThreadLock:
acquire: Callable[[bool, float], bool]
release: Callable[[], None]
def __enter__(self) -> bool: ...
def __exit__(self, *args: object) -> None: ...
def __exit__(self, *args: Unused) -> None: ...

class ForkAwareLocal(threading.local): ...

Expand Down
4 changes: 2 additions & 2 deletions stdlib/nntplib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import datetime
import socket
import ssl
import sys
from _typeshed import Self
from _typeshed import Self, Unused
from builtins import list as _list # conflicts with a method named "list"
from collections.abc import Iterable
from typing import IO, Any, NamedTuple
Expand Down Expand Up @@ -73,7 +73,7 @@ class NNTP:
timeout: float = ...,
) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: object) -> None: ...
def __exit__(self, *args: Unused) -> None: ...
def getwelcome(self) -> str: ...
def getcapabilities(self) -> dict[str, _list[str]]: ...
def set_debuglevel(self, level: int) -> None: ...
Expand Down
5 changes: 3 additions & 2 deletions stdlib/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ from _typeshed import (
StrOrBytesPath,
StrPath,
SupportsLenAndGetItem,
Unused,
WriteableBuffer,
structseq,
)
Expand Down Expand Up @@ -730,7 +731,7 @@ def rmdir(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> None: ...

class _ScandirIterator(Iterator[DirEntry[AnyStr]], AbstractContextManager[_ScandirIterator[AnyStr]]):
def __next__(self) -> DirEntry[AnyStr]: ...
def __exit__(self, *args: object) -> None: ...
def __exit__(self, *args: Unused) -> None: ...
def close(self) -> None: ...

@overload
Expand Down Expand Up @@ -997,7 +998,7 @@ if sys.version_info >= (3, 8):
def __init__(self, path: str | None, cookie: _T, remove_dll_directory: Callable[[_T], object]) -> None: ...
def close(self) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: object) -> None: ...
def __exit__(self, *args: Unused) -> None: ...

def add_dll_directory(path: str) -> _AddedDllDirectory: ...
if sys.platform == "linux":
Expand Down
2 changes: 1 addition & 1 deletion stdlib/pydoc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def replace(text: AnyStr, *pairs: AnyStr) -> AnyStr: ...
def cram(text: str, maxlen: int) -> str: ...
def stripid(text: str) -> str: ...
def allmethods(cl: type) -> MutableMapping[str, MethodType]: ...
def visiblename(name: str, all: Container[str] | None = ..., obj: object | None = ...) -> bool: ...
def visiblename(name: str, all: Container[str] | None = ..., obj: object = ...) -> bool: ...
def classify_class_attrs(object: object) -> list[tuple[str, str, type, str]]: ...
def ispackage(path: str) -> bool: ...
def source_synopsis(file: IO[AnyStr]) -> AnyStr | None: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/runpy.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Self
from _typeshed import Self, Unused
from types import ModuleType
from typing import Any

Expand All @@ -9,13 +9,13 @@ class _TempModule:
module: ModuleType
def __init__(self, mod_name: str) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: object) -> None: ...
def __exit__(self, *args: Unused) -> None: ...

class _ModifiedArgv0:
value: Any
def __init__(self, value: Any) -> None: ...
def __enter__(self) -> None: ...
def __exit__(self, *args: object) -> None: ...
def __exit__(self, *args: Unused) -> None: ...

def run_module(
mod_name: str, init_globals: dict[str, Any] | None = ..., run_name: str | None = ..., alter_sys: bool = ...
Expand Down
Loading