Skip to content

Commit 17408ee

Browse files
authored
fix the __init__ of several C-classes (#13211)
1 parent bfb9a91 commit 17408ee

23 files changed

+160
-111
lines changed

stdlib/_asyncio.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn
6565
self,
6666
coro: _TaskCompatibleCoro[_T_co],
6767
*,
68-
loop: AbstractEventLoop = ...,
68+
loop: AbstractEventLoop | None = None,
6969
name: str | None = ...,
7070
context: Context | None = None,
7171
eager_start: bool = False,
@@ -75,13 +75,13 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn
7575
self,
7676
coro: _TaskCompatibleCoro[_T_co],
7777
*,
78-
loop: AbstractEventLoop = ...,
78+
loop: AbstractEventLoop | None = None,
7979
name: str | None = ...,
8080
context: Context | None = None,
8181
) -> None: ...
8282
else:
8383
def __init__(
84-
self, coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop = ..., name: str | None = ...
84+
self, coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop | None = None, name: str | None = ...
8585
) -> None: ...
8686

8787
if sys.version_info >= (3, 12):

stdlib/_blake2.pyi

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class blake2b:
2222
digest_size: int
2323
name: str
2424
if sys.version_info >= (3, 9):
25-
def __init__(
26-
self,
25+
def __new__(
26+
cls,
2727
data: ReadableBuffer = b"",
2828
/,
2929
*,
@@ -39,10 +39,10 @@ class blake2b:
3939
inner_size: int = 0,
4040
last_node: bool = False,
4141
usedforsecurity: bool = True,
42-
) -> None: ...
42+
) -> Self: ...
4343
else:
44-
def __init__(
45-
self,
44+
def __new__(
45+
cls,
4646
data: ReadableBuffer = b"",
4747
/,
4848
*,
@@ -57,7 +57,7 @@ class blake2b:
5757
node_depth: int = 0,
5858
inner_size: int = 0,
5959
last_node: bool = False,
60-
) -> None: ...
60+
) -> Self: ...
6161

6262
def copy(self) -> Self: ...
6363
def digest(self) -> bytes: ...
@@ -74,8 +74,8 @@ class blake2s:
7474
digest_size: int
7575
name: str
7676
if sys.version_info >= (3, 9):
77-
def __init__(
78-
self,
77+
def __new__(
78+
cls,
7979
data: ReadableBuffer = b"",
8080
/,
8181
*,
@@ -91,10 +91,10 @@ class blake2s:
9191
inner_size: int = 0,
9292
last_node: bool = False,
9393
usedforsecurity: bool = True,
94-
) -> None: ...
94+
) -> Self: ...
9595
else:
96-
def __init__(
97-
self,
96+
def __new__(
97+
cls,
9898
data: ReadableBuffer = b"",
9999
/,
100100
*,
@@ -109,7 +109,7 @@ class blake2s:
109109
node_depth: int = 0,
110110
inner_size: int = 0,
111111
last_node: bool = False,
112-
) -> None: ...
112+
) -> Self: ...
113113

114114
def copy(self) -> Self: ...
115115
def digest(self) -> bytes: ...

stdlib/_bz2.pyi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import sys
12
from _typeshed import ReadableBuffer
23
from typing import final
4+
from typing_extensions import Self
35

46
@final
57
class BZ2Compressor:
6-
def __init__(self, compresslevel: int = 9) -> None: ...
8+
if sys.version_info >= (3, 12):
9+
def __new__(cls, compresslevel: int = 9, /) -> Self: ...
10+
else:
11+
def __init__(self, compresslevel: int = 9, /) -> None: ...
12+
713
def compress(self, data: ReadableBuffer, /) -> bytes: ...
814
def flush(self) -> bytes: ...
915

stdlib/_contextvars.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from collections.abc import Callable, Iterator, Mapping
33
from typing import Any, ClassVar, Generic, TypeVar, final, overload
4-
from typing_extensions import ParamSpec
4+
from typing_extensions import ParamSpec, Self
55

66
if sys.version_info >= (3, 9):
77
from types import GenericAlias
@@ -13,9 +13,9 @@ _P = ParamSpec("_P")
1313
@final
1414
class ContextVar(Generic[_T]):
1515
@overload
16-
def __init__(self, name: str) -> None: ...
16+
def __new__(cls, name: str) -> Self: ...
1717
@overload
18-
def __init__(self, name: str, *, default: _T) -> None: ...
18+
def __new__(cls, name: str, *, default: _T) -> Self: ...
1919
def __hash__(self) -> int: ...
2020
@property
2121
def name(self) -> str: ...

stdlib/_csv.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class Dialect:
3232
lineterminator: str
3333
quoting: _QuotingType
3434
strict: bool
35-
def __init__(
36-
self,
35+
def __new__(
36+
cls,
3737
dialect: _DialectLike | None = ...,
3838
delimiter: str = ",",
3939
doublequote: bool = True,
@@ -43,7 +43,7 @@ class Dialect:
4343
quoting: _QuotingType = 0,
4444
skipinitialspace: bool = False,
4545
strict: bool = False,
46-
) -> None: ...
46+
) -> Self: ...
4747

4848
if sys.version_info >= (3, 10):
4949
# This class calls itself _csv.reader.

stdlib/_ctypes.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,18 @@ class CFuncPtr(_PointerLike, _CData, metaclass=_PyCFuncPtrType):
169169
# Abstract attribute that must be defined on subclasses
170170
_flags_: ClassVar[int]
171171
@overload
172-
def __init__(self) -> None: ...
172+
def __new__(cls) -> Self: ...
173173
@overload
174-
def __init__(self, address: int, /) -> None: ...
174+
def __new__(cls, address: int, /) -> Self: ...
175175
@overload
176-
def __init__(self, callable: Callable[..., Any], /) -> None: ...
176+
def __new__(cls, callable: Callable[..., Any], /) -> Self: ...
177177
@overload
178-
def __init__(self, func_spec: tuple[str | int, CDLL], paramflags: tuple[_PF, ...] | None = ..., /) -> None: ...
178+
def __new__(cls, func_spec: tuple[str | int, CDLL], paramflags: tuple[_PF, ...] | None = ..., /) -> Self: ...
179179
if sys.platform == "win32":
180180
@overload
181-
def __init__(
182-
self, vtbl_index: int, name: str, paramflags: tuple[_PF, ...] | None = ..., iid: _CData | _CDataType | None = ..., /
183-
) -> None: ...
181+
def __new__(
182+
cls, vtbl_index: int, name: str, paramflags: tuple[_PF, ...] | None = ..., iid: _CData | _CDataType | None = ..., /
183+
) -> Self: ...
184184

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

stdlib/_io.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class BufferedRandom(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore
112112
def truncate(self, pos: int | None = None, /) -> int: ...
113113

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

118118
class _TextIOBase(_IOBase):

stdlib/_json.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections.abc import Callable
22
from typing import Any, final
3+
from typing_extensions import Self
34

45
@final
56
class make_encoder:
@@ -19,8 +20,8 @@ class make_encoder:
1920
def encoder(self) -> Callable[[str], str]: ...
2021
@property
2122
def item_separator(self) -> str: ...
22-
def __init__(
23-
self,
23+
def __new__(
24+
cls,
2425
markers: dict[int, Any] | None,
2526
default: Callable[[Any], Any],
2627
encoder: Callable[[str], str],
@@ -30,7 +31,7 @@ class make_encoder:
3031
sort_keys: bool,
3132
skipkeys: bool,
3233
allow_nan: bool,
33-
) -> None: ...
34+
) -> Self: ...
3435
def __call__(self, obj: object, _current_indent_level: int) -> Any: ...
3536

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

4849
def encode_basestring(s: str, /) -> str: ...

stdlib/_lzma.pyi

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import sys
12
from _typeshed import ReadableBuffer
23
from collections.abc import Mapping, Sequence
34
from typing import Any, Final, final
4-
from typing_extensions import TypeAlias
5+
from typing_extensions import Self, TypeAlias
56

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

@@ -36,7 +37,11 @@ PRESET_EXTREME: int # v big number
3637

3738
@final
3839
class LZMADecompressor:
39-
def __init__(self, format: int | None = ..., memlimit: int | None = ..., filters: _FilterChain | None = ...) -> None: ...
40+
if sys.version_info >= (3, 12):
41+
def __new__(cls, format: int | None = ..., memlimit: int | None = ..., filters: _FilterChain | None = ...) -> Self: ...
42+
else:
43+
def __init__(self, format: int | None = ..., memlimit: int | None = ..., filters: _FilterChain | None = ...) -> None: ...
44+
4045
def decompress(self, data: ReadableBuffer, max_length: int = -1) -> bytes: ...
4146
@property
4247
def check(self) -> int: ...
@@ -49,9 +54,15 @@ class LZMADecompressor:
4954

5055
@final
5156
class LZMACompressor:
52-
def __init__(
53-
self, format: int | None = ..., check: int = ..., preset: int | None = ..., filters: _FilterChain | None = ...
54-
) -> None: ...
57+
if sys.version_info >= (3, 12):
58+
def __new__(
59+
cls, format: int | None = ..., check: int = ..., preset: int | None = ..., filters: _FilterChain | None = ...
60+
) -> Self: ...
61+
else:
62+
def __init__(
63+
self, format: int | None = ..., check: int = ..., preset: int | None = ..., filters: _FilterChain | None = ...
64+
) -> None: ...
65+
5566
def compress(self, data: ReadableBuffer, /) -> bytes: ...
5667
def flush(self) -> bytes: ...
5768

stdlib/_pickle.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class Pickler:
6666
self,
6767
file: SupportsWrite[bytes],
6868
protocol: int | None = None,
69-
*,
7069
fix_imports: bool = True,
7170
buffer_callback: _BufferCallback = None,
7271
) -> None: ...

0 commit comments

Comments
 (0)