mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 04:54:47 +08:00
Use typing_extensions.Self in the stdlib (#9694)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import Self, SupportsKeysAndGetItem
|
||||
from _typeshed import SupportsKeysAndGetItem
|
||||
from _weakref import (
|
||||
CallableProxyType as CallableProxyType,
|
||||
ProxyType as ProxyType,
|
||||
@@ -12,7 +12,7 @@ from _weakref import (
|
||||
from _weakrefset import WeakSet as WeakSet
|
||||
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping
|
||||
from typing import Any, Generic, TypeVar, overload
|
||||
from typing_extensions import ParamSpec
|
||||
from typing_extensions import ParamSpec, Self
|
||||
|
||||
__all__ = [
|
||||
"ref",
|
||||
@@ -41,7 +41,7 @@ _P = ParamSpec("_P")
|
||||
ProxyTypes: tuple[type[Any], ...]
|
||||
|
||||
class WeakMethod(ref[_CallableT], Generic[_CallableT]):
|
||||
def __new__(cls: type[Self], meth: _CallableT, callback: Callable[[_CallableT], object] | None = None) -> Self: ...
|
||||
def __new__(cls, meth: _CallableT, callback: Callable[[_CallableT], object] | None = None) -> Self: ...
|
||||
def __call__(self) -> _CallableT | None: ...
|
||||
def __eq__(self, other: object) -> bool: ...
|
||||
def __ne__(self, other: object) -> bool: ...
|
||||
@@ -63,7 +63,7 @@ class WeakValueDictionary(MutableMapping[_KT, _VT]):
|
||||
def __iter__(self) -> Iterator[_KT]: ...
|
||||
def copy(self) -> WeakValueDictionary[_KT, _VT]: ...
|
||||
__copy__ = copy
|
||||
def __deepcopy__(self: Self, memo: Any) -> Self: ...
|
||||
def __deepcopy__(self, memo: Any) -> Self: ...
|
||||
# These are incompatible with Mapping
|
||||
def keys(self) -> Iterator[_KT]: ... # type: ignore[override]
|
||||
def values(self) -> Iterator[_VT]: ... # type: ignore[override]
|
||||
@@ -80,14 +80,14 @@ class WeakValueDictionary(MutableMapping[_KT, _VT]):
|
||||
def __ror__(self, other: Mapping[_T1, _T2]) -> WeakValueDictionary[_KT | _T1, _VT | _T2]: ...
|
||||
# WeakValueDictionary.__ior__ should be kept roughly in line with MutableMapping.update()
|
||||
@overload # type: ignore[misc]
|
||||
def __ior__(self: Self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ...
|
||||
def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ...
|
||||
@overload
|
||||
def __ior__(self: Self, other: Iterable[tuple[_KT, _VT]]) -> Self: ...
|
||||
def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ...
|
||||
|
||||
class KeyedRef(ref[_T], Generic[_KT, _T]):
|
||||
key: _KT
|
||||
# This __new__ method uses a non-standard name for the "cls" parameter
|
||||
def __new__(type: type[Self], ob: _T, callback: Callable[[_T], Any], key: _KT) -> Self: ...
|
||||
def __new__(type, ob: _T, callback: Callable[[_T], Any], key: _KT) -> Self: ...
|
||||
def __init__(self, ob: _T, callback: Callable[[_T], Any], key: _KT) -> None: ...
|
||||
|
||||
class WeakKeyDictionary(MutableMapping[_KT, _VT]):
|
||||
@@ -103,7 +103,7 @@ class WeakKeyDictionary(MutableMapping[_KT, _VT]):
|
||||
def __iter__(self) -> Iterator[_KT]: ...
|
||||
def copy(self) -> WeakKeyDictionary[_KT, _VT]: ...
|
||||
__copy__ = copy
|
||||
def __deepcopy__(self: Self, memo: Any) -> Self: ...
|
||||
def __deepcopy__(self, memo: Any) -> Self: ...
|
||||
# These are incompatible with Mapping
|
||||
def keys(self) -> Iterator[_KT]: ... # type: ignore[override]
|
||||
def values(self) -> Iterator[_VT]: ... # type: ignore[override]
|
||||
@@ -123,9 +123,9 @@ class WeakKeyDictionary(MutableMapping[_KT, _VT]):
|
||||
def __ror__(self, other: Mapping[_T1, _T2]) -> WeakKeyDictionary[_KT | _T1, _VT | _T2]: ...
|
||||
# WeakKeyDictionary.__ior__ should be kept roughly in line with MutableMapping.update()
|
||||
@overload # type: ignore[misc]
|
||||
def __ior__(self: Self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ...
|
||||
def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ...
|
||||
@overload
|
||||
def __ior__(self: Self, other: Iterable[tuple[_KT, _VT]]) -> Self: ...
|
||||
def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ...
|
||||
|
||||
class finalize: # TODO: This is a good candidate for to be a `Generic[_P, _T]` class
|
||||
def __init__(self, __obj: object, __func: Callable[_P, Any], *args: _P.args, **kwargs: _P.kwargs) -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user