Use typing_extensions.Self in the stdlib (#9694)

This commit is contained in:
Alex Waygood
2023-02-09 09:12:13 +00:00
committed by GitHub
parent 10086c06a1
commit 9ed39d8796
98 changed files with 627 additions and 654 deletions

View File

@@ -1,13 +1,13 @@
import logging
import sys
import unittest.result
from _typeshed import Self, SupportsDunderGE, SupportsDunderGT, SupportsDunderLE, SupportsDunderLT, SupportsRSub, SupportsSub
from _typeshed import SupportsDunderGE, SupportsDunderGT, SupportsDunderLE, SupportsDunderLT, SupportsRSub, SupportsSub
from collections.abc import Callable, Container, Iterable, Mapping, Sequence, Set as AbstractSet
from contextlib import AbstractContextManager
from re import Pattern
from types import TracebackType
from typing import Any, AnyStr, ClassVar, Generic, NamedTuple, NoReturn, Protocol, SupportsAbs, SupportsRound, TypeVar, overload
from typing_extensions import ParamSpec, TypeAlias
from typing_extensions import ParamSpec, Self, TypeAlias
from warnings import WarningMessage
if sys.version_info >= (3, 9):
@@ -304,7 +304,7 @@ class FunctionTestCase(TestCase):
class _AssertRaisesContext(Generic[_E]):
exception: _E
def __enter__(self: Self) -> Self: ...
def __enter__(self) -> Self: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, tb: TracebackType | None
) -> bool: ...
@@ -316,7 +316,7 @@ class _AssertWarnsContext:
filename: str
lineno: int
warnings: list[WarningMessage]
def __enter__(self: Self) -> Self: ...
def __enter__(self) -> Self: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, tb: TracebackType | None
) -> None: ...

View File

@@ -1,10 +1,9 @@
import sys
from _typeshed import Self
from collections.abc import Awaitable, Callable, Coroutine, Iterable, Mapping, Sequence
from contextlib import _GeneratorContextManager
from types import TracebackType
from typing import Any, Generic, TypeVar, overload
from typing_extensions import Literal, TypeAlias
from typing_extensions import Literal, Self, TypeAlias
_T = TypeVar("_T")
_TT = TypeVar("_TT", bound=type[Any])
@@ -68,12 +67,7 @@ _CallValue: TypeAlias = str | tuple[Any, ...] | Mapping[str, Any] | _ArgsKwargs
class _Call(tuple[Any, ...]):
def __new__(
cls: type[Self],
value: _CallValue = ...,
name: str | None = "",
parent: Any | None = None,
two: bool = False,
from_kall: bool = True,
cls, value: _CallValue = ..., name: str | None = "", parent: Any | None = None, two: bool = False, from_kall: bool = True
) -> Self: ...
name: Any
parent: Any
@@ -108,7 +102,7 @@ class Base:
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
class NonCallableMock(Base, Any):
def __new__(__cls: type[Self], *args: Any, **kw: Any) -> Self: ...
def __new__(__cls, *args: Any, **kw: Any) -> Self: ...
def __init__(
self,
spec: list[str] | object | type[object] | None = None,
@@ -437,9 +431,9 @@ def mock_open(mock: Any | None = None, read_data: Any = "") -> Any: ...
class PropertyMock(Mock):
if sys.version_info >= (3, 8):
def __get__(self: Self, obj: _T, obj_type: type[_T] | None = None) -> Self: ...
def __get__(self, obj: _T, obj_type: type[_T] | None = None) -> Self: ...
else:
def __get__(self: Self, obj: _T, obj_type: type[_T] | None) -> Self: ...
def __get__(self, obj: _T, obj_type: type[_T] | None) -> Self: ...
def __set__(self, obj: Any, value: Any) -> None: ...