mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 21:14:48 +08:00
Replace __init__ with __new__ in builtins and types (#10761)
This commit is contained in:
@@ -867,7 +867,7 @@ class memoryview(Sequence[int]):
|
||||
def contiguous(self) -> bool: ...
|
||||
@property
|
||||
def nbytes(self) -> int: ...
|
||||
def __init__(self, obj: ReadableBuffer) -> None: ...
|
||||
def __new__(cls, obj: ReadableBuffer) -> Self: ...
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
self, __exc_type: type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None
|
||||
@@ -946,9 +946,9 @@ class slice:
|
||||
@property
|
||||
def stop(self) -> Any: ...
|
||||
@overload
|
||||
def __init__(self, __stop: Any) -> None: ...
|
||||
def __new__(cls, __stop: Any) -> Self: ...
|
||||
@overload
|
||||
def __init__(self, __start: Any, __stop: Any, __step: Any = ...) -> None: ...
|
||||
def __new__(cls, __start: Any, __stop: Any, __step: Any = ...) -> Self: ...
|
||||
def __eq__(self, __value: object) -> bool: ...
|
||||
__hash__: ClassVar[None] # type: ignore[assignment]
|
||||
def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ...
|
||||
@@ -1203,7 +1203,7 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]):
|
||||
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
|
||||
|
||||
class enumerate(Iterator[tuple[int, _T]], Generic[_T]):
|
||||
def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ...
|
||||
def __new__(cls, iterable: Iterable[_T], start: int = ...) -> Self: ...
|
||||
def __iter__(self) -> Self: ...
|
||||
def __next__(self) -> tuple[int, _T]: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
@@ -1218,9 +1218,9 @@ class range(Sequence[int]):
|
||||
@property
|
||||
def step(self) -> int: ...
|
||||
@overload
|
||||
def __init__(self, __stop: SupportsIndex) -> None: ...
|
||||
def __new__(cls, __stop: SupportsIndex) -> Self: ...
|
||||
@overload
|
||||
def __init__(self, __start: SupportsIndex, __stop: SupportsIndex, __step: SupportsIndex = ...) -> None: ...
|
||||
def __new__(cls, __start: SupportsIndex, __stop: SupportsIndex, __step: SupportsIndex = ...) -> Self: ...
|
||||
def count(self, __value: int) -> int: ...
|
||||
def index(self, __value: int) -> int: ... # type: ignore[override]
|
||||
def __len__(self) -> int: ...
|
||||
@@ -1413,11 +1413,11 @@ def exit(code: sys._ExitCode = None) -> NoReturn: ...
|
||||
|
||||
class filter(Iterator[_T], Generic[_T]):
|
||||
@overload
|
||||
def __init__(self, __function: None, __iterable: Iterable[_T | None]) -> None: ...
|
||||
def __new__(cls, __function: None, __iterable: Iterable[_T | None]) -> Self: ...
|
||||
@overload
|
||||
def __init__(self, __function: Callable[[_S], TypeGuard[_T]], __iterable: Iterable[_S]) -> None: ...
|
||||
def __new__(cls, __function: Callable[[_S], TypeGuard[_T]], __iterable: Iterable[_S]) -> Self: ...
|
||||
@overload
|
||||
def __init__(self, __function: Callable[[_T], Any], __iterable: Iterable[_T]) -> None: ...
|
||||
def __new__(cls, __function: Callable[[_T], Any], __iterable: Iterable[_T]) -> Self: ...
|
||||
def __iter__(self) -> Self: ...
|
||||
def __next__(self) -> _T: ...
|
||||
|
||||
@@ -1472,35 +1472,35 @@ def locals() -> dict[str, Any]: ...
|
||||
|
||||
class map(Iterator[_S], Generic[_S]):
|
||||
@overload
|
||||
def __init__(self, __func: Callable[[_T1], _S], __iter1: Iterable[_T1]) -> None: ...
|
||||
def __new__(cls, __func: Callable[[_T1], _S], __iter1: Iterable[_T1]) -> Self: ...
|
||||
@overload
|
||||
def __init__(self, __func: Callable[[_T1, _T2], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> None: ...
|
||||
def __new__(cls, __func: Callable[[_T1, _T2], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> Self: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self, __func: Callable[[_T1, _T2, _T3], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3]
|
||||
) -> None: ...
|
||||
def __new__(
|
||||
cls, __func: Callable[[_T1, _T2, _T3], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3]
|
||||
) -> Self: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
def __new__(
|
||||
cls,
|
||||
__func: Callable[[_T1, _T2, _T3, _T4], _S],
|
||||
__iter1: Iterable[_T1],
|
||||
__iter2: Iterable[_T2],
|
||||
__iter3: Iterable[_T3],
|
||||
__iter4: Iterable[_T4],
|
||||
) -> None: ...
|
||||
) -> Self: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
def __new__(
|
||||
cls,
|
||||
__func: Callable[[_T1, _T2, _T3, _T4, _T5], _S],
|
||||
__iter1: Iterable[_T1],
|
||||
__iter2: Iterable[_T2],
|
||||
__iter3: Iterable[_T3],
|
||||
__iter4: Iterable[_T4],
|
||||
__iter5: Iterable[_T5],
|
||||
) -> None: ...
|
||||
) -> Self: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
def __new__(
|
||||
cls,
|
||||
__func: Callable[..., _S],
|
||||
__iter1: Iterable[Any],
|
||||
__iter2: Iterable[Any],
|
||||
@@ -1509,7 +1509,7 @@ class map(Iterator[_S], Generic[_S]):
|
||||
__iter5: Iterable[Any],
|
||||
__iter6: Iterable[Any],
|
||||
*iterables: Iterable[Any],
|
||||
) -> None: ...
|
||||
) -> Self: ...
|
||||
def __iter__(self) -> Self: ...
|
||||
def __next__(self) -> _S: ...
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ _VT_co = TypeVar("_VT_co", covariant=True)
|
||||
@final
|
||||
class _Cell:
|
||||
if sys.version_info >= (3, 8):
|
||||
def __init__(self, __contents: object = ...) -> None: ...
|
||||
def __new__(cls, __contents: object = ...) -> Self: ...
|
||||
|
||||
def __eq__(self, __value: object) -> bool: ...
|
||||
__hash__: ClassVar[None] # type: ignore[assignment]
|
||||
@@ -96,14 +96,14 @@ class FunctionType:
|
||||
__type_params__: tuple[TypeVar | ParamSpec | TypeVarTuple, ...]
|
||||
|
||||
__module__: str
|
||||
def __init__(
|
||||
self,
|
||||
def __new__(
|
||||
cls,
|
||||
code: CodeType,
|
||||
globals: dict[str, Any],
|
||||
name: str | None = ...,
|
||||
argdefs: tuple[object, ...] | None = ...,
|
||||
closure: tuple[_Cell, ...] | None = ...,
|
||||
) -> None: ...
|
||||
) -> Self: ...
|
||||
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
|
||||
@overload
|
||||
def __get__(self, __instance: None, __owner: type) -> FunctionType: ...
|
||||
@@ -162,8 +162,8 @@ class CodeType:
|
||||
def co_positions(self) -> Iterable[tuple[int | None, int | None, int | None, int | None]]: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
def __init__(
|
||||
self,
|
||||
def __new__(
|
||||
cls,
|
||||
__argcount: int,
|
||||
__posonlyargcount: int,
|
||||
__kwonlyargcount: int,
|
||||
@@ -182,10 +182,10 @@ class CodeType:
|
||||
__exceptiontable: bytes,
|
||||
__freevars: tuple[str, ...] = ...,
|
||||
__cellvars: tuple[str, ...] = ...,
|
||||
) -> None: ...
|
||||
) -> Self: ...
|
||||
elif sys.version_info >= (3, 10):
|
||||
def __init__(
|
||||
self,
|
||||
def __new__(
|
||||
cls,
|
||||
__argcount: int,
|
||||
__posonlyargcount: int,
|
||||
__kwonlyargcount: int,
|
||||
@@ -202,10 +202,10 @@ class CodeType:
|
||||
__linetable: bytes,
|
||||
__freevars: tuple[str, ...] = ...,
|
||||
__cellvars: tuple[str, ...] = ...,
|
||||
) -> None: ...
|
||||
) -> Self: ...
|
||||
elif sys.version_info >= (3, 8):
|
||||
def __init__(
|
||||
self,
|
||||
def __new__(
|
||||
cls,
|
||||
__argcount: int,
|
||||
__posonlyargcount: int,
|
||||
__kwonlyargcount: int,
|
||||
@@ -222,10 +222,10 @@ class CodeType:
|
||||
__lnotab: bytes,
|
||||
__freevars: tuple[str, ...] = ...,
|
||||
__cellvars: tuple[str, ...] = ...,
|
||||
) -> None: ...
|
||||
) -> Self: ...
|
||||
else:
|
||||
def __init__(
|
||||
self,
|
||||
def __new__(
|
||||
cls,
|
||||
__argcount: int,
|
||||
__kwonlyargcount: int,
|
||||
__nlocals: int,
|
||||
@@ -241,7 +241,7 @@ class CodeType:
|
||||
__lnotab: bytes,
|
||||
__freevars: tuple[str, ...] = ...,
|
||||
__cellvars: tuple[str, ...] = ...,
|
||||
) -> None: ...
|
||||
) -> Self: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
def replace(
|
||||
self,
|
||||
@@ -311,7 +311,7 @@ class CodeType:
|
||||
@final
|
||||
class MappingProxyType(Mapping[_KT, _VT_co], Generic[_KT, _VT_co]):
|
||||
__hash__: ClassVar[None] # type: ignore[assignment]
|
||||
def __init__(self, mapping: SupportsKeysAndGetItem[_KT, _VT_co]) -> None: ...
|
||||
def __new__(cls, mapping: SupportsKeysAndGetItem[_KT, _VT_co]) -> Self: ...
|
||||
def __getitem__(self, __key: _KT) -> _VT_co: ...
|
||||
def __iter__(self) -> Iterator[_KT]: ...
|
||||
def __len__(self) -> int: ...
|
||||
@@ -444,7 +444,7 @@ class MethodType:
|
||||
def __name__(self) -> str: ... # inherited from the added function
|
||||
@property
|
||||
def __qualname__(self) -> str: ... # inherited from the added function
|
||||
def __init__(self, __func: Callable[..., Any], __obj: object) -> None: ...
|
||||
def __new__(cls, __func: Callable[..., Any], __obj: object) -> Self: ...
|
||||
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
|
||||
def __eq__(self, __value: object) -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
@@ -513,7 +513,7 @@ class ClassMethodDescriptorType:
|
||||
|
||||
@final
|
||||
class TracebackType:
|
||||
def __init__(self, tb_next: TracebackType | None, tb_frame: FrameType, tb_lasti: int, tb_lineno: int) -> None: ...
|
||||
def __new__(cls, tb_next: TracebackType | None, tb_frame: FrameType, tb_lasti: int, tb_lineno: int) -> Self: ...
|
||||
tb_next: TracebackType | None
|
||||
# the rest are read-only even in 3.7
|
||||
@property
|
||||
@@ -610,7 +610,7 @@ if sys.version_info >= (3, 9):
|
||||
def __args__(self) -> tuple[Any, ...]: ...
|
||||
@property
|
||||
def __parameters__(self) -> tuple[Any, ...]: ...
|
||||
def __init__(self, origin: type, args: Any) -> None: ...
|
||||
def __new__(cls, origin: type, args: Any) -> Self: ...
|
||||
def __getitem__(self, __typeargs: Any) -> GenericAlias: ...
|
||||
def __eq__(self, __value: object) -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
|
||||
Reference in New Issue
Block a user