stdlib: Fix more signatures with unrepresentable defaults (#11007)

This commit is contained in:
Jelle Zijlstra
2023-11-09 18:20:09 -08:00
committed by GitHub
parent b8932899ea
commit 4deef7550f
6 changed files with 48 additions and 25 deletions

View File

@@ -1,13 +1,36 @@
import sys
from typing import Any, overload
_defaultaction: str
_onceregistry: dict[Any, Any]
filters: list[tuple[str, str | None, type[Warning], str | None, int]]
@overload
def warn(message: str, category: type[Warning] | None = None, stacklevel: int = 1, source: Any | None = None) -> None: ...
@overload
def warn(message: Warning, category: Any = None, stacklevel: int = 1, source: Any | None = None) -> None: ...
if sys.version_info >= (3, 12):
@overload
def warn(
message: str,
category: type[Warning] | None = None,
stacklevel: int = 1,
source: Any | None = None,
*,
skip_file_prefixes: tuple[str, ...] = (),
) -> None: ...
@overload
def warn(
message: Warning,
category: Any = None,
stacklevel: int = 1,
source: Any | None = None,
*,
skip_file_prefixes: tuple[str, ...] = (),
) -> None: ...
else:
@overload
def warn(message: str, category: type[Warning] | None = None, stacklevel: int = 1, source: Any | None = None) -> None: ...
@overload
def warn(message: Warning, category: Any = None, stacklevel: int = 1, source: Any | None = None) -> None: ...
@overload
def warn_explicit(
message: str,

View File

@@ -1434,9 +1434,9 @@ def getattr(__o: object, __name: str, __default: None) -> Any | None: ...
@overload
def getattr(__o: object, __name: str, __default: bool) -> Any | bool: ...
@overload
def getattr(__o: object, name: str, __default: list[Any]) -> Any | list[Any]: ...
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]: ...
def getattr(__o: object, __name: str, __default: dict[Any, Any]) -> Any | dict[Any, Any]: ...
@overload
def getattr(__o: object, __name: str, __default: _T) -> Any | _T: ...
def globals() -> dict[str, Any]: ...
@@ -1451,13 +1451,13 @@ class _GetItemIterable(Protocol[_T_co]):
def __getitem__(self, __i: int) -> _T_co: ...
@overload
def iter(__iterable: SupportsIter[_SupportsNextT]) -> _SupportsNextT: ...
def iter(__object: SupportsIter[_SupportsNextT]) -> _SupportsNextT: ...
@overload
def iter(__iterable: _GetItemIterable[_T]) -> Iterator[_T]: ...
def iter(__object: _GetItemIterable[_T]) -> Iterator[_T]: ...
@overload
def iter(__function: Callable[[], _T | None], __sentinel: None) -> Iterator[_T]: ...
def iter(__object: Callable[[], _T | None], __sentinel: None) -> Iterator[_T]: ...
@overload
def iter(__function: Callable[[], _T], __sentinel: object) -> Iterator[_T]: ...
def iter(__object: Callable[[], _T], __sentinel: object) -> Iterator[_T]: ...
# Keep this alias in sync with unittest.case._ClassInfo
if sys.version_info >= (3, 10):

View File

@@ -213,7 +213,7 @@ class StreamWriter(Codec):
def reset(self) -> None: ...
def __enter__(self) -> Self: ...
def __exit__(self, type: type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None) -> None: ...
def __getattr__(self, name: str, getattr: Callable[[str], Any] = ...) -> Any: ...
def __getattr__(self, name: str, getattr: Callable[[Any, str], Any] = ...) -> Any: ...
class StreamReader(Codec):
stream: _ReadableStream
@@ -227,7 +227,7 @@ class StreamReader(Codec):
def __exit__(self, type: type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None) -> None: ...
def __iter__(self) -> Self: ...
def __next__(self) -> str: ...
def __getattr__(self, name: str, getattr: Callable[[str], Any] = ...) -> Any: ...
def __getattr__(self, name: str, getattr: Callable[[Any, str], Any] = ...) -> Any: ...
# Doesn't actually inherit from TextIO, but wraps a BinaryIO to provide text reading and writing
# and delegates attributes to the underlying binary stream with __getattr__.

View File

@@ -372,6 +372,13 @@ class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
def setdefault(self: OrderedDict[_KT, _T | None], key: _KT, default: None = None) -> _T | None: ...
@overload
def setdefault(self, key: _KT, default: _VT) -> _VT: ...
# Same as dict.pop, but accepts keyword arguments
@overload
def pop(self, key: _KT) -> _VT: ...
@overload
def pop(self, key: _KT, default: _VT) -> _VT: ...
@overload
def pop(self, key: _KT, default: _T) -> _VT | _T: ...
def __eq__(self, __value: object) -> bool: ...
if sys.version_info >= (3, 9):
@overload

View File

@@ -23,17 +23,10 @@ class ContextVar(Generic[_T]):
def name(self) -> str: ...
@overload
def get(self) -> _T: ...
if sys.version_info >= (3, 8):
@overload
def get(self, default: _T) -> _T: ...
@overload
def get(self, default: _D) -> _D | _T: ...
else:
@overload
def get(self, __default: _T) -> _T: ...
@overload
def get(self, __default: _D) -> _D | _T: ...
@overload
def get(self, __default: _T) -> _T: ...
@overload
def get(self, __default: _D) -> _D | _T: ...
def set(self, __value: _T) -> Token[_T]: ...
def reset(self, __token: Token[_T]) -> None: ...
if sys.version_info >= (3, 9):

View File

@@ -349,9 +349,9 @@ class Connection:
def create_function(self, name: str, num_params: int, func: Callable[..., _SqliteData] | None) -> None: ...
@overload
def cursor(self, cursorClass: None = None) -> Cursor: ...
def cursor(self, factory: None = None) -> Cursor: ...
@overload
def cursor(self, cursorClass: Callable[[Connection], _CursorT]) -> _CursorT: ...
def cursor(self, factory: Callable[[Connection], _CursorT]) -> _CursorT: ...
def execute(self, __sql: str, __parameters: _Parameters = ...) -> Cursor: ...
def executemany(self, __sql: str, __parameters: Iterable[_Parameters]) -> Cursor: ...
def executescript(self, __sql_script: str) -> Cursor: ...