stdlib: add argument default values (#9501)

This commit is contained in:
Jelle Zijlstra
2023-01-18 00:37:34 -08:00
committed by GitHub
parent 6cb934291f
commit ddfaca3200
272 changed files with 2529 additions and 2467 deletions

View File

@@ -12,7 +12,7 @@ __all__ = ["Client", "Listener", "Pipe", "wait"]
_Address: TypeAlias = Union[str, tuple[str, int]]
class _ConnectionBase:
def __init__(self, handle: SupportsIndex, readable: bool = ..., writable: bool = ...) -> None: ...
def __init__(self, handle: SupportsIndex, readable: bool = True, writable: bool = True) -> None: ...
@property
def closed(self) -> bool: ... # undocumented
@property
@@ -21,10 +21,10 @@ class _ConnectionBase:
def writable(self) -> bool: ... # undocumented
def fileno(self) -> int: ...
def close(self) -> None: ...
def send_bytes(self, buf: ReadableBuffer, offset: int = ..., size: int | None = ...) -> None: ...
def send_bytes(self, buf: ReadableBuffer, offset: int = 0, size: int | None = None) -> None: ...
def send(self, obj: Any) -> None: ...
def recv_bytes(self, maxlength: int | None = ...) -> bytes: ...
def recv_bytes_into(self, buf: Any, offset: int = ...) -> int: ...
def recv_bytes(self, maxlength: int | None = None) -> bytes: ...
def recv_bytes_into(self, buf: Any, offset: int = 0) -> int: ...
def recv(self) -> Any: ...
def poll(self, timeout: float | None = ...) -> bool: ...
def __enter__(self: Self) -> Self: ...
@@ -39,7 +39,7 @@ if sys.platform == "win32":
class Listener:
def __init__(
self, address: _Address | None = ..., family: str | None = ..., backlog: int = ..., authkey: bytes | None = ...
self, address: _Address | None = None, family: str | None = None, backlog: int = 1, authkey: bytes | None = None
) -> None: ...
def accept(self) -> Connection: ...
def close(self) -> None: ...
@@ -55,15 +55,15 @@ class Listener:
def deliver_challenge(connection: Connection, authkey: bytes) -> None: ...
def answer_challenge(connection: Connection, authkey: bytes) -> None: ...
def wait(
object_list: Iterable[Connection | socket.socket | int], timeout: float | None = ...
object_list: Iterable[Connection | socket.socket | int], timeout: float | None = None
) -> list[Connection | socket.socket | int]: ...
def Client(address: _Address, family: str | None = ..., authkey: bytes | None = ...) -> Connection: ...
def Client(address: _Address, family: str | None = None, authkey: bytes | None = None) -> Connection: ...
# N.B. Keep this in sync with multiprocessing.context.BaseContext.Pipe.
# _ConnectionBase is the common base class of Connection and PipeConnection
# and can be used in cross-platform code.
if sys.platform != "win32":
def Pipe(duplex: bool = ...) -> tuple[Connection, Connection]: ...
def Pipe(duplex: bool = True) -> tuple[Connection, Connection]: ...
else:
def Pipe(duplex: bool = ...) -> tuple[PipeConnection, PipeConnection]: ...

View File

@@ -52,28 +52,28 @@ class BaseContext:
# _ConnectionBase is the common base class of Connection and PipeConnection
# and can be used in cross-platform code.
if sys.platform != "win32":
def Pipe(self, duplex: bool = ...) -> tuple[Connection, Connection]: ...
def Pipe(self, duplex: bool = True) -> tuple[Connection, Connection]: ...
else:
def Pipe(self, duplex: bool = ...) -> tuple[PipeConnection, PipeConnection]: ...
def Barrier(
self, parties: int, action: Callable[..., object] | None = ..., timeout: float | None = ...
self, parties: int, action: Callable[..., object] | None = None, timeout: float | None = None
) -> synchronize.Barrier: ...
def BoundedSemaphore(self, value: int = ...) -> synchronize.BoundedSemaphore: ...
def Condition(self, lock: _LockLike | None = ...) -> synchronize.Condition: ...
def BoundedSemaphore(self, value: int = 1) -> synchronize.BoundedSemaphore: ...
def Condition(self, lock: _LockLike | None = None) -> synchronize.Condition: ...
def Event(self) -> synchronize.Event: ...
def Lock(self) -> synchronize.Lock: ...
def RLock(self) -> synchronize.RLock: ...
def Semaphore(self, value: int = ...) -> synchronize.Semaphore: ...
def Queue(self, maxsize: int = ...) -> queues.Queue[Any]: ...
def JoinableQueue(self, maxsize: int = ...) -> queues.JoinableQueue[Any]: ...
def Semaphore(self, value: int = 1) -> synchronize.Semaphore: ...
def Queue(self, maxsize: int = 0) -> queues.Queue[Any]: ...
def JoinableQueue(self, maxsize: int = 0) -> queues.JoinableQueue[Any]: ...
def SimpleQueue(self) -> queues.SimpleQueue[Any]: ...
def Pool(
self,
processes: int | None = ...,
initializer: Callable[..., object] | None = ...,
processes: int | None = None,
initializer: Callable[..., object] | None = None,
initargs: Iterable[Any] = ...,
maxtasksperchild: int | None = ...,
maxtasksperchild: int | None = None,
) -> _Pool: ...
@overload
def RawValue(self, typecode_or_type: type[_CT], *args: Any) -> _CT: ...
@@ -107,7 +107,7 @@ class BaseContext:
) -> Any: ...
def freeze_support(self) -> None: ...
def get_logger(self) -> Logger: ...
def log_to_stderr(self, level: _LoggingLevel | None = ...) -> Logger: ...
def log_to_stderr(self, level: _LoggingLevel | None = None) -> Logger: ...
def allow_connection_pickling(self) -> None: ...
def set_executable(self, executable: str) -> None: ...
def set_forkserver_preload(self, module_names: list[str]) -> None: ...
@@ -134,7 +134,7 @@ class BaseContext:
def get_start_method(self, allow_none: Literal[False] = ...) -> str: ...
@overload
def get_start_method(self, allow_none: bool) -> str | None: ...
def set_start_method(self, method: str | None, force: bool = ...) -> None: ...
def set_start_method(self, method: str | None, force: bool = False) -> None: ...
@property
def reducer(self) -> str: ...
@reducer.setter
@@ -149,7 +149,7 @@ class Process(BaseProcess):
class DefaultContext(BaseContext):
Process: ClassVar[type[Process]]
def __init__(self, context: BaseContext) -> None: ...
def get_start_method(self, allow_none: bool = ...) -> str: ...
def get_start_method(self, allow_none: bool = False) -> str: ...
def get_all_start_methods(self) -> list[str]: ...
if sys.version_info < (3, 8):
__all__: ClassVar[list[str]]

View File

@@ -47,9 +47,9 @@ class DummyProcess(threading.Thread):
def exitcode(self) -> Literal[0] | None: ...
def __init__(
self,
group: Any = ...,
target: Callable[..., object] | None = ...,
name: str | None = ...,
group: Any = None,
target: Callable[..., object] | None = None,
name: str | None = None,
args: Iterable[Any] = ...,
kwargs: Mapping[str, Any] = ...,
) -> None: ...
@@ -65,11 +65,13 @@ class Value:
_typecode: Any
_value: Any
value: Any
def __init__(self, typecode: Any, value: Any, lock: Any = ...) -> None: ...
def __init__(self, typecode: Any, value: Any, lock: Any = True) -> None: ...
def Array(typecode: Any, sequence: Sequence[Any], lock: Any = ...) -> array.array[Any]: ...
def Array(typecode: Any, sequence: Sequence[Any], lock: Any = True) -> array.array[Any]: ...
def Manager() -> Any: ...
def Pool(processes: int | None = ..., initializer: Callable[..., object] | None = ..., initargs: Iterable[Any] = ...) -> Any: ...
def Pool(
processes: int | None = None, initializer: Callable[..., object] | None = None, initargs: Iterable[Any] = ...
) -> Any: ...
def active_children() -> list[Any]: ...
current_process = threading.current_thread

View File

@@ -33,9 +33,9 @@ class Listener:
def __exit__(
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_tb: TracebackType | None
) -> None: ...
def __init__(self, address: _Address | None = ..., family: int | None = ..., backlog: int = ...) -> None: ...
def __init__(self, address: _Address | None = None, family: int | None = None, backlog: int = 1) -> None: ...
def accept(self) -> Connection: ...
def close(self) -> None: ...
def Client(address: _Address) -> Connection: ...
def Pipe(duplex: bool = ...) -> tuple[Connection, Connection]: ...
def Pipe(duplex: bool = True) -> tuple[Connection, Connection]: ...

View File

@@ -18,8 +18,8 @@ def main(
listener_fd: int | None,
alive_r: FileDescriptorLike,
preload: Sequence[str],
main_path: str | None = ...,
sys_path: Unused = ...,
main_path: str | None = None,
sys_path: Unused = None,
) -> None: ...
def read_signed(fd: int) -> Any: ...
def write_signed(fd: int, n: int) -> None: ...

View File

@@ -15,7 +15,7 @@ class Arena:
def __init__(self, size: int) -> None: ...
else:
fd: int
def __init__(self, size: int, fd: int = ...) -> None: ...
def __init__(self, size: int, fd: int = -1) -> None: ...
_Block: TypeAlias = tuple[Arena, int, int]
@@ -27,7 +27,7 @@ if sys.platform != "win32":
def rebuild_arena(size: int, dupfd: _SupportsDetach) -> Arena: ...
class Heap:
def __init__(self, size: int = ...) -> None: ...
def __init__(self, size: int = 16384) -> None: ...
def free(self, block: _Block) -> None: ...
def malloc(self, size: int) -> _Block: ...

View File

@@ -47,11 +47,11 @@ class BaseProxy:
self,
token: Any,
serializer: str,
manager: Any = ...,
authkey: AnyStr | None = ...,
exposed: Any = ...,
incref: bool = ...,
manager_owned: bool = ...,
manager: Any = None,
authkey: AnyStr | None = None,
exposed: Any = None,
incref: bool = True,
manager_owned: bool = False,
) -> None: ...
def __deepcopy__(self, memo: Any | None) -> Any: ...
def _callmethod(self, methodname: str, args: tuple[Any, ...] = ..., kwds: dict[Any, Any] = ...) -> None: ...
@@ -132,10 +132,10 @@ class BaseManager:
if sys.version_info >= (3, 11):
def __init__(
self,
address: Any | None = ...,
authkey: bytes | None = ...,
serializer: str = ...,
ctx: BaseContext | None = ...,
address: Any | None = None,
authkey: bytes | None = None,
serializer: str = "pickle",
ctx: BaseContext | None = None,
*,
shutdown_timeout: float = ...,
) -> None: ...
@@ -146,20 +146,20 @@ class BaseManager:
def get_server(self) -> Server: ...
def connect(self) -> None: ...
def start(self, initializer: Callable[..., object] | None = ..., initargs: Iterable[Any] = ...) -> None: ...
def start(self, initializer: Callable[..., object] | None = None, initargs: Iterable[Any] = ...) -> None: ...
def shutdown(self) -> None: ... # only available after start() was called
def join(self, timeout: float | None = ...) -> None: ... # undocumented
def join(self, timeout: float | None = None) -> None: ... # undocumented
@property
def address(self) -> Any: ...
@classmethod
def register(
cls,
typeid: str,
callable: Callable[..., object] | None = ...,
proxytype: Any = ...,
exposed: Sequence[str] | None = ...,
method_to_typeid: Mapping[str, str] | None = ...,
create_method: bool = ...,
callable: Callable[..., object] | None = None,
proxytype: Any = None,
exposed: Sequence[str] | None = None,
method_to_typeid: Mapping[str, str] | None = None,
create_method: bool = True,
) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(

View File

@@ -26,8 +26,8 @@ class ApplyResult(Generic[_T]):
error_callback: Callable[[BaseException], object] | None,
) -> None: ...
def get(self, timeout: float | None = ...) -> _T: ...
def wait(self, timeout: float | None = ...) -> None: ...
def get(self, timeout: float | None = None) -> _T: ...
def wait(self, timeout: float | None = None) -> None: ...
def ready(self) -> bool: ...
def successful(self) -> bool: ...
if sys.version_info >= (3, 9):
@@ -63,19 +63,19 @@ class IMapIterator(Iterator[_T]):
def __init__(self, cache: dict[int, IMapIterator[Any]]) -> None: ...
def __iter__(self: Self) -> Self: ...
def next(self, timeout: float | None = ...) -> _T: ...
def __next__(self, timeout: float | None = ...) -> _T: ...
def next(self, timeout: float | None = None) -> _T: ...
def __next__(self, timeout: float | None = None) -> _T: ...
class IMapUnorderedIterator(IMapIterator[_T]): ...
class Pool:
def __init__(
self,
processes: int | None = ...,
initializer: Callable[..., object] | None = ...,
processes: int | None = None,
initializer: Callable[..., object] | None = None,
initargs: Iterable[Any] = ...,
maxtasksperchild: int | None = ...,
context: Any | None = ...,
maxtasksperchild: int | None = None,
context: Any | None = None,
) -> None: ...
def apply(self, func: Callable[..., _T], args: Iterable[Any] = ..., kwds: Mapping[str, Any] = ...) -> _T: ...
def apply_async(
@@ -83,30 +83,28 @@ class Pool:
func: Callable[..., _T],
args: Iterable[Any] = ...,
kwds: Mapping[str, Any] = ...,
callback: Callable[[_T], object] | None = ...,
error_callback: Callable[[BaseException], object] | None = ...,
callback: Callable[[_T], object] | None = None,
error_callback: Callable[[BaseException], object] | None = None,
) -> AsyncResult[_T]: ...
def map(self, func: Callable[[_S], _T], iterable: Iterable[_S], chunksize: int | None = ...) -> list[_T]: ...
def map(self, func: Callable[[_S], _T], iterable: Iterable[_S], chunksize: int | None = None) -> list[_T]: ...
def map_async(
self,
func: Callable[[_S], _T],
iterable: Iterable[_S],
chunksize: int | None = ...,
callback: Callable[[_T], object] | None = ...,
error_callback: Callable[[BaseException], object] | None = ...,
chunksize: int | None = None,
callback: Callable[[_T], object] | None = None,
error_callback: Callable[[BaseException], object] | None = None,
) -> MapResult[_T]: ...
def imap(self, func: Callable[[_S], _T], iterable: Iterable[_S], chunksize: int | None = ...) -> IMapIterator[_T]: ...
def imap_unordered(
self, func: Callable[[_S], _T], iterable: Iterable[_S], chunksize: int | None = ...
) -> IMapIterator[_T]: ...
def starmap(self, func: Callable[..., _T], iterable: Iterable[Iterable[Any]], chunksize: int | None = ...) -> list[_T]: ...
def imap(self, func: Callable[[_S], _T], iterable: Iterable[_S], chunksize: int | None = 1) -> IMapIterator[_T]: ...
def imap_unordered(self, func: Callable[[_S], _T], iterable: Iterable[_S], chunksize: int | None = 1) -> IMapIterator[_T]: ...
def starmap(self, func: Callable[..., _T], iterable: Iterable[Iterable[Any]], chunksize: int | None = None) -> list[_T]: ...
def starmap_async(
self,
func: Callable[..., _T],
iterable: Iterable[Iterable[Any]],
chunksize: int | None = ...,
callback: Callable[[_T], object] | None = ...,
error_callback: Callable[[BaseException], object] | None = ...,
chunksize: int | None = None,
callback: Callable[[_T], object] | None = None,
error_callback: Callable[[BaseException], object] | None = None,
) -> AsyncResult[list[_T]]: ...
def close(self) -> None: ...
def terminate(self) -> None: ...
@@ -118,7 +116,7 @@ class Pool:
class ThreadPool(Pool):
def __init__(
self, processes: int | None = ..., initializer: Callable[..., object] | None = ..., initargs: Iterable[Any] = ...
self, processes: int | None = None, initializer: Callable[..., object] | None = None, initargs: Iterable[Any] = ...
) -> None: ...
# undocumented

View File

@@ -16,8 +16,8 @@ if sys.platform != "win32":
def __init__(self, process_obj: BaseProcess) -> None: ...
def duplicate_for_child(self, fd: int) -> int: ...
def poll(self, flag: int = ...) -> int | None: ...
def wait(self, timeout: float | None = ...) -> int | None: ...
def poll(self, flag: int = 1) -> int | None: ...
def wait(self, timeout: float | None = None) -> int | None: ...
def terminate(self) -> None: ...
def kill(self) -> None: ...
def close(self) -> None: ...

View File

@@ -14,20 +14,20 @@ class BaseProcess:
_identity: tuple[int, ...] # undocumented
def __init__(
self,
group: None = ...,
target: Callable[..., object] | None = ...,
name: str | None = ...,
group: None = None,
target: Callable[..., object] | None = None,
name: str | None = None,
args: Iterable[Any] = ...,
kwargs: Mapping[str, Any] = ...,
*,
daemon: bool | None = ...,
daemon: bool | None = None,
) -> None: ...
def run(self) -> None: ...
def start(self) -> None: ...
def terminate(self) -> None: ...
def kill(self) -> None: ...
def close(self) -> None: ...
def join(self, timeout: float | None = ...) -> None: ...
def join(self, timeout: float | None = None) -> None: ...
def is_alive(self) -> bool: ...
@property
def exitcode(self) -> int | None: ...

View File

@@ -12,9 +12,9 @@ _T = TypeVar("_T")
class Queue(queue.Queue[_T]):
# FIXME: `ctx` is a circular dependency and it's not actually optional.
# It's marked as such to be able to use the generic Queue in __init__.pyi.
def __init__(self, maxsize: int = ..., *, ctx: Any = ...) -> None: ...
def get(self, block: bool = ..., timeout: float | None = ...) -> _T: ...
def put(self, obj: _T, block: bool = ..., timeout: float | None = ...) -> None: ...
def __init__(self, maxsize: int = 0, *, ctx: Any = ...) -> None: ...
def get(self, block: bool = True, timeout: float | None = None) -> _T: ...
def put(self, obj: _T, block: bool = True, timeout: float | None = None) -> None: ...
def put_nowait(self, item: _T) -> None: ...
def get_nowait(self) -> _T: ...
def close(self) -> None: ...

View File

@@ -24,12 +24,12 @@ class ForkingPickler(pickle.Pickler):
@classmethod
def register(cls, type: Type, reduce: Callable[[Any], _ReducedType]) -> None: ...
@classmethod
def dumps(cls, obj: Any, protocol: int | None = ...) -> memoryview: ...
def dumps(cls, obj: Any, protocol: int | None = None) -> memoryview: ...
loads = pickle.loads
register = ForkingPickler.register
def dump(obj: Any, file: SupportsWrite[bytes], protocol: int | None = ...) -> None: ...
def dump(obj: Any, file: SupportsWrite[bytes], protocol: int | None = None) -> None: ...
if sys.platform == "win32":
if sys.version_info >= (3, 8):

View File

@@ -17,4 +17,4 @@ else:
def __init__(self, fd: int) -> None: ...
def detach(self) -> int: ...
def stop(timeout: float | None = ...) -> None: ...
def stop(timeout: float | None = None) -> None: ...

View File

@@ -11,7 +11,7 @@ __all__ = ["SharedMemory", "ShareableList"]
_SLT = TypeVar("_SLT", int, float, bool, str, bytes, None)
class SharedMemory:
def __init__(self, name: str | None = ..., create: bool = ..., size: int = ...) -> None: ...
def __init__(self, name: str | None = None, create: bool = False, size: int = 0) -> None: ...
@property
def buf(self) -> memoryview: ...
@property

View File

@@ -78,7 +78,7 @@ class _AcquireFunc(Protocol):
class SynchronizedBase(Generic[_CT]):
acquire: _AcquireFunc
release: Callable[[], None]
def __init__(self, obj: Any, lock: _LockLike | None = ..., ctx: Any | None = ...) -> None: ...
def __init__(self, obj: Any, lock: _LockLike | None = None, ctx: Any | None = None) -> None: ...
def __reduce__(self) -> tuple[Callable[[Any, _LockLike], SynchronizedBase[Any]], tuple[Any, _LockLike]]: ...
def get_obj(self) -> _CT: ...
def get_lock(self) -> _LockLike: ...

View File

@@ -20,7 +20,7 @@ def get_executable() -> str: ...
def is_forking(argv: Sequence[str]) -> bool: ...
def freeze_support() -> None: ...
def get_command_line(**kwds: Any) -> list[str]: ...
def spawn_main(pipe_handle: int, parent_pid: int | None = ..., tracker_fd: int | None = ...) -> None: ...
def spawn_main(pipe_handle: int, parent_pid: int | None = None, tracker_fd: int | None = None) -> None: ...
# undocumented
def _main(fd: int) -> Any: ...

View File

@@ -11,18 +11,18 @@ _LockLike: TypeAlias = Lock | RLock
class Barrier(threading.Barrier):
def __init__(
self, parties: int, action: Callable[[], object] | None = ..., timeout: float | None = ..., *ctx: BaseContext
self, parties: int, action: Callable[[], object] | None = None, timeout: float | None = None, *ctx: BaseContext
) -> None: ...
class BoundedSemaphore(Semaphore):
def __init__(self, value: int = ..., *, ctx: BaseContext) -> None: ...
def __init__(self, value: int = 1, *, ctx: BaseContext) -> None: ...
class Condition(AbstractContextManager[bool]):
def __init__(self, lock: _LockLike | None = ..., *, ctx: BaseContext) -> None: ...
def notify(self, n: int = ...) -> None: ...
def __init__(self, lock: _LockLike | None = None, *, ctx: BaseContext) -> None: ...
def notify(self, n: int = 1) -> None: ...
def notify_all(self) -> None: ...
def wait(self, timeout: float | None = ...) -> bool: ...
def wait_for(self, predicate: Callable[[], bool], timeout: float | None = ...) -> bool: ...
def wait(self, timeout: float | None = None) -> bool: ...
def wait_for(self, predicate: Callable[[], bool], timeout: float | None = None) -> bool: ...
def acquire(self, block: bool = ..., timeout: float | None = ...) -> bool: ...
def release(self) -> None: ...
def __exit__(
@@ -34,7 +34,7 @@ class Event:
def is_set(self) -> bool: ...
def set(self) -> None: ...
def clear(self) -> None: ...
def wait(self, timeout: float | None = ...) -> bool: ...
def wait(self, timeout: float | None = None) -> bool: ...
class Lock(SemLock):
def __init__(self, *, ctx: BaseContext) -> None: ...
@@ -43,7 +43,7 @@ class RLock(SemLock):
def __init__(self, *, ctx: BaseContext) -> None: ...
class Semaphore(SemLock):
def __init__(self, value: int = ..., *, ctx: BaseContext) -> None: ...
def __init__(self, value: int = 1, *, ctx: BaseContext) -> None: ...
# Not part of public API
class SemLock(AbstractContextManager[bool]):

View File

@@ -37,7 +37,7 @@ def debug(msg: object, *args: object) -> None: ...
def info(msg: object, *args: object) -> None: ...
def sub_warning(msg: object, *args: object) -> None: ...
def get_logger() -> Logger: ...
def log_to_stderr(level: _LoggingLevel | None = ...) -> Logger: ...
def log_to_stderr(level: _LoggingLevel | None = None) -> Logger: ...
def is_abstract_socket_namespace(address: str | bytes | None) -> bool: ...
abstract_sockets_supported: bool
@@ -51,12 +51,12 @@ class Finalize:
obj: Incomplete | None,
callback: Callable[..., Incomplete],
args: Sequence[Any] = ...,
kwargs: Mapping[str, Any] | None = ...,
exitpriority: int | None = ...,
kwargs: Mapping[str, Any] | None = None,
exitpriority: int | None = None,
) -> None: ...
def __call__(
self,
wr: Unused = ...,
wr: Unused = None,
_finalizer_registry: MutableMapping[Incomplete, Incomplete] = ...,
sub_debug: Callable[..., object] = ...,
getpid: Callable[[], int] = ...,