Skip to content

Commit

Permalink
fix the __init__ of several C-classes (#13211)
Browse files Browse the repository at this point in the history
  • Loading branch information
tungol authored Dec 23, 2024
1 parent bfb9a91 commit 17408ee
Show file tree
Hide file tree
Showing 23 changed files with 160 additions and 111 deletions.
6 changes: 3 additions & 3 deletions stdlib/_asyncio.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn
self,
coro: _TaskCompatibleCoro[_T_co],
*,
loop: AbstractEventLoop = ...,
loop: AbstractEventLoop | None = None,
name: str | None = ...,
context: Context | None = None,
eager_start: bool = False,
Expand All @@ -75,13 +75,13 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn
self,
coro: _TaskCompatibleCoro[_T_co],
*,
loop: AbstractEventLoop = ...,
loop: AbstractEventLoop | None = None,
name: str | None = ...,
context: Context | None = None,
) -> None: ...
else:
def __init__(
self, coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop = ..., name: str | None = ...
self, coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop | None = None, name: str | None = ...
) -> None: ...

if sys.version_info >= (3, 12):
Expand Down
24 changes: 12 additions & 12 deletions stdlib/_blake2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class blake2b:
digest_size: int
name: str
if sys.version_info >= (3, 9):
def __init__(
self,
def __new__(
cls,
data: ReadableBuffer = b"",
/,
*,
Expand All @@ -39,10 +39,10 @@ class blake2b:
inner_size: int = 0,
last_node: bool = False,
usedforsecurity: bool = True,
) -> None: ...
) -> Self: ...
else:
def __init__(
self,
def __new__(
cls,
data: ReadableBuffer = b"",
/,
*,
Expand All @@ -57,7 +57,7 @@ class blake2b:
node_depth: int = 0,
inner_size: int = 0,
last_node: bool = False,
) -> None: ...
) -> Self: ...

def copy(self) -> Self: ...
def digest(self) -> bytes: ...
Expand All @@ -74,8 +74,8 @@ class blake2s:
digest_size: int
name: str
if sys.version_info >= (3, 9):
def __init__(
self,
def __new__(
cls,
data: ReadableBuffer = b"",
/,
*,
Expand All @@ -91,10 +91,10 @@ class blake2s:
inner_size: int = 0,
last_node: bool = False,
usedforsecurity: bool = True,
) -> None: ...
) -> Self: ...
else:
def __init__(
self,
def __new__(
cls,
data: ReadableBuffer = b"",
/,
*,
Expand All @@ -109,7 +109,7 @@ class blake2s:
node_depth: int = 0,
inner_size: int = 0,
last_node: bool = False,
) -> None: ...
) -> Self: ...

def copy(self) -> Self: ...
def digest(self) -> bytes: ...
Expand Down
8 changes: 7 additions & 1 deletion stdlib/_bz2.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import sys
from _typeshed import ReadableBuffer
from typing import final
from typing_extensions import Self

@final
class BZ2Compressor:
def __init__(self, compresslevel: int = 9) -> None: ...
if sys.version_info >= (3, 12):
def __new__(cls, compresslevel: int = 9, /) -> Self: ...
else:
def __init__(self, compresslevel: int = 9, /) -> None: ...

def compress(self, data: ReadableBuffer, /) -> bytes: ...
def flush(self) -> bytes: ...

Expand Down
6 changes: 3 additions & 3 deletions stdlib/_contextvars.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from collections.abc import Callable, Iterator, Mapping
from typing import Any, ClassVar, Generic, TypeVar, final, overload
from typing_extensions import ParamSpec
from typing_extensions import ParamSpec, Self

if sys.version_info >= (3, 9):
from types import GenericAlias
Expand All @@ -13,9 +13,9 @@ _P = ParamSpec("_P")
@final
class ContextVar(Generic[_T]):
@overload
def __init__(self, name: str) -> None: ...
def __new__(cls, name: str) -> Self: ...
@overload
def __init__(self, name: str, *, default: _T) -> None: ...
def __new__(cls, name: str, *, default: _T) -> Self: ...
def __hash__(self) -> int: ...
@property
def name(self) -> str: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/_csv.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Dialect:
lineterminator: str
quoting: _QuotingType
strict: bool
def __init__(
self,
def __new__(
cls,
dialect: _DialectLike | None = ...,
delimiter: str = ",",
doublequote: bool = True,
Expand All @@ -43,7 +43,7 @@ class Dialect:
quoting: _QuotingType = 0,
skipinitialspace: bool = False,
strict: bool = False,
) -> None: ...
) -> Self: ...

if sys.version_info >= (3, 10):
# This class calls itself _csv.reader.
Expand Down
14 changes: 7 additions & 7 deletions stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,18 @@ class CFuncPtr(_PointerLike, _CData, metaclass=_PyCFuncPtrType):
# Abstract attribute that must be defined on subclasses
_flags_: ClassVar[int]
@overload
def __init__(self) -> None: ...
def __new__(cls) -> Self: ...
@overload
def __init__(self, address: int, /) -> None: ...
def __new__(cls, address: int, /) -> Self: ...
@overload
def __init__(self, callable: Callable[..., Any], /) -> None: ...
def __new__(cls, callable: Callable[..., Any], /) -> Self: ...
@overload
def __init__(self, func_spec: tuple[str | int, CDLL], paramflags: tuple[_PF, ...] | None = ..., /) -> None: ...
def __new__(cls, func_spec: tuple[str | int, CDLL], paramflags: tuple[_PF, ...] | None = ..., /) -> Self: ...
if sys.platform == "win32":
@overload
def __init__(
self, vtbl_index: int, name: str, paramflags: tuple[_PF, ...] | None = ..., iid: _CData | _CDataType | None = ..., /
) -> None: ...
def __new__(
cls, vtbl_index: int, name: str, paramflags: tuple[_PF, ...] | None = ..., iid: _CData | _CDataType | None = ..., /
) -> Self: ...

def __call__(self, *args: Any, **kwargs: Any) -> Any: ...

Expand Down
2 changes: 1 addition & 1 deletion stdlib/_io.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class BufferedRandom(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore
def truncate(self, pos: int | None = None, /) -> int: ...

class BufferedRWPair(BufferedIOBase, _BufferedIOBase):
def __init__(self, reader: RawIOBase, writer: RawIOBase, buffer_size: int = 8192) -> None: ...
def __init__(self, reader: RawIOBase, writer: RawIOBase, buffer_size: int = 8192, /) -> None: ...
def peek(self, size: int = 0, /) -> bytes: ...

class _TextIOBase(_IOBase):
Expand Down
9 changes: 5 additions & 4 deletions stdlib/_json.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Callable
from typing import Any, final
from typing_extensions import Self

@final
class make_encoder:
Expand All @@ -19,8 +20,8 @@ class make_encoder:
def encoder(self) -> Callable[[str], str]: ...
@property
def item_separator(self) -> str: ...
def __init__(
self,
def __new__(
cls,
markers: dict[int, Any] | None,
default: Callable[[Any], Any],
encoder: Callable[[str], str],
Expand All @@ -30,7 +31,7 @@ class make_encoder:
sort_keys: bool,
skipkeys: bool,
allow_nan: bool,
) -> None: ...
) -> Self: ...
def __call__(self, obj: object, _current_indent_level: int) -> Any: ...

@final
Expand All @@ -42,7 +43,7 @@ class make_scanner:
parse_float: Any
strict: bool
# TODO: 'context' needs the attrs above (ducktype), but not __call__.
def __init__(self, context: make_scanner) -> None: ...
def __new__(cls, context: make_scanner) -> Self: ...
def __call__(self, string: str, index: int) -> tuple[Any, int]: ...

def encode_basestring(s: str, /) -> str: ...
Expand Down
21 changes: 16 additions & 5 deletions stdlib/_lzma.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import sys
from _typeshed import ReadableBuffer
from collections.abc import Mapping, Sequence
from typing import Any, Final, final
from typing_extensions import TypeAlias
from typing_extensions import Self, TypeAlias

_FilterChain: TypeAlias = Sequence[Mapping[str, Any]]

Expand Down Expand Up @@ -36,7 +37,11 @@ PRESET_EXTREME: int # v big number

@final
class LZMADecompressor:
def __init__(self, format: int | None = ..., memlimit: int | None = ..., filters: _FilterChain | None = ...) -> None: ...
if sys.version_info >= (3, 12):
def __new__(cls, format: int | None = ..., memlimit: int | None = ..., filters: _FilterChain | None = ...) -> Self: ...
else:
def __init__(self, format: int | None = ..., memlimit: int | None = ..., filters: _FilterChain | None = ...) -> None: ...

def decompress(self, data: ReadableBuffer, max_length: int = -1) -> bytes: ...
@property
def check(self) -> int: ...
Expand All @@ -49,9 +54,15 @@ class LZMADecompressor:

@final
class LZMACompressor:
def __init__(
self, format: int | None = ..., check: int = ..., preset: int | None = ..., filters: _FilterChain | None = ...
) -> None: ...
if sys.version_info >= (3, 12):
def __new__(
cls, format: int | None = ..., check: int = ..., preset: int | None = ..., filters: _FilterChain | None = ...
) -> Self: ...
else:
def __init__(
self, format: int | None = ..., check: int = ..., preset: int | None = ..., filters: _FilterChain | None = ...
) -> None: ...

def compress(self, data: ReadableBuffer, /) -> bytes: ...
def flush(self) -> bytes: ...

Expand Down
1 change: 0 additions & 1 deletion stdlib/_pickle.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class Pickler:
self,
file: SupportsWrite[bytes],
protocol: int | None = None,
*,
fix_imports: bool = True,
buffer_callback: _BufferCallback = None,
) -> None: ...
Expand Down
20 changes: 11 additions & 9 deletions stdlib/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ class array(MutableSequence[_T]):
@property
def itemsize(self) -> int: ...
@overload
def __init__(self: array[int], typecode: _IntTypeCode, initializer: bytes | bytearray | Iterable[int] = ..., /) -> None: ...
def __new__(
cls: type[array[int]], typecode: _IntTypeCode, initializer: bytes | bytearray | Iterable[int] = ..., /
) -> array[int]: ...
@overload
def __init__(
self: array[float], typecode: _FloatTypeCode, initializer: bytes | bytearray | Iterable[float] = ..., /
) -> None: ...
def __new__(
cls: type[array[float]], typecode: _FloatTypeCode, initializer: bytes | bytearray | Iterable[float] = ..., /
) -> array[float]: ...
@overload
def __init__(
self: array[str], typecode: _UnicodeTypeCode, initializer: bytes | bytearray | Iterable[str] = ..., /
) -> None: ...
def __new__(
cls: type[array[str]], typecode: _UnicodeTypeCode, initializer: bytes | bytearray | Iterable[str] = ..., /
) -> array[str]: ...
@overload
def __init__(self, typecode: str, initializer: Iterable[_T], /) -> None: ...
def __new__(cls, typecode: str, initializer: Iterable[_T], /) -> Self: ...
@overload
def __init__(self, typecode: str, initializer: bytes | bytearray = ..., /) -> None: ...
def __new__(cls, typecode: str, initializer: bytes | bytearray = ..., /) -> Self: ...
def append(self, v: _T, /) -> None: ...
def buffer_info(self) -> tuple[int, int]: ...
def byteswap(self) -> None: ...
Expand Down
12 changes: 6 additions & 6 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1489,18 +1489,18 @@ def locals() -> dict[str, Any]: ...

class map(Generic[_S]):
@overload
def __new__(cls, func: Callable[[_T1], _S], iter1: Iterable[_T1], /) -> Self: ...
def __new__(cls, func: Callable[[_T1], _S], iterable: Iterable[_T1], /) -> Self: ...
@overload
def __new__(cls, func: Callable[[_T1, _T2], _S], iter1: Iterable[_T1], iter2: Iterable[_T2], /) -> Self: ...
def __new__(cls, func: Callable[[_T1, _T2], _S], iterable: Iterable[_T1], iter2: Iterable[_T2], /) -> Self: ...
@overload
def __new__(
cls, func: Callable[[_T1, _T2, _T3], _S], iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], /
cls, func: Callable[[_T1, _T2, _T3], _S], iterable: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], /
) -> Self: ...
@overload
def __new__(
cls,
func: Callable[[_T1, _T2, _T3, _T4], _S],
iter1: Iterable[_T1],
iterable: Iterable[_T1],
iter2: Iterable[_T2],
iter3: Iterable[_T3],
iter4: Iterable[_T4],
Expand All @@ -1510,7 +1510,7 @@ class map(Generic[_S]):
def __new__(
cls,
func: Callable[[_T1, _T2, _T3, _T4, _T5], _S],
iter1: Iterable[_T1],
iterable: Iterable[_T1],
iter2: Iterable[_T2],
iter3: Iterable[_T3],
iter4: Iterable[_T4],
Expand All @@ -1521,7 +1521,7 @@ class map(Generic[_S]):
def __new__(
cls,
func: Callable[..., _S],
iter1: Iterable[Any],
iterable: Iterable[Any],
iter2: Iterable[Any],
iter3: Iterable[Any],
iter4: Iterable[Any],
Expand Down
2 changes: 1 addition & 1 deletion stdlib/datetime.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class timezone(tzinfo):
utc: ClassVar[timezone]
min: ClassVar[timezone]
max: ClassVar[timezone]
def __init__(self, offset: timedelta, name: str = ...) -> None: ...
def __new__(cls, offset: timedelta, name: str = ...) -> Self: ...
def tzname(self, dt: datetime | None, /) -> str: ...
def utcoffset(self, dt: datetime | None, /) -> timedelta: ...
def dst(self, dt: datetime | None, /) -> None: ...
Expand Down
1 change: 0 additions & 1 deletion stdlib/decimal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ class Context:
clamp: int | None = ...,
flags: None | dict[_TrapType, bool] | Container[_TrapType] = ...,
traps: None | dict[_TrapType, bool] | Container[_TrapType] = ...,
_ignored_flags: list[_TrapType] | None = ...,
) -> None: ...
def __reduce__(self) -> tuple[type[Self], tuple[Any, ...]]: ...
def clear_flags(self) -> None: ...
Expand Down
Loading

0 comments on commit 17408ee

Please sign in to comment.