Use PEP 585 syntax wherever possible (#6717)

This commit is contained in:
Alex Waygood
2021-12-28 10:31:43 +00:00
committed by GitHub
parent e6cb341d94
commit 8d5d2520ac
237 changed files with 966 additions and 1069 deletions

View File

@@ -19,7 +19,6 @@ from typing import (
NoReturn,
Pattern,
Sequence,
Tuple,
Type,
TypeVar,
overload,
@@ -102,8 +101,8 @@ class TestCase:
def assertIsNotNone(self, obj: Any, msg: Any = ...) -> None: ...
def assertIn(self, member: Any, container: Iterable[Any] | Container[Any], msg: Any = ...) -> None: ...
def assertNotIn(self, member: Any, container: Iterable[Any] | Container[Any], msg: Any = ...) -> None: ...
def assertIsInstance(self, obj: Any, cls: type | Tuple[type, ...], msg: Any = ...) -> None: ...
def assertNotIsInstance(self, obj: Any, cls: type | Tuple[type, ...], msg: Any = ...) -> None: ...
def assertIsInstance(self, obj: Any, cls: type | tuple[type, ...], msg: Any = ...) -> None: ...
def assertNotIsInstance(self, obj: Any, cls: type | tuple[type, ...], msg: Any = ...) -> None: ...
def assertGreater(self, a: Any, b: Any, msg: Any = ...) -> None: ...
def assertGreaterEqual(self, a: Any, b: Any, msg: Any = ...) -> None: ...
def assertLess(self, a: Any, b: Any, msg: Any = ...) -> None: ...
@@ -111,17 +110,17 @@ class TestCase:
@overload
def assertRaises( # type: ignore[misc]
self,
expected_exception: Type[BaseException] | Tuple[Type[BaseException], ...],
expected_exception: Type[BaseException] | tuple[Type[BaseException], ...],
callable: Callable[..., Any],
*args: Any,
**kwargs: Any,
) -> None: ...
@overload
def assertRaises(self, expected_exception: Type[_E] | Tuple[Type[_E], ...], msg: Any = ...) -> _AssertRaisesContext[_E]: ...
def assertRaises(self, expected_exception: Type[_E] | tuple[Type[_E], ...], msg: Any = ...) -> _AssertRaisesContext[_E]: ...
@overload
def assertRaisesRegex( # type: ignore[misc]
self,
expected_exception: Type[BaseException] | Tuple[Type[BaseException], ...],
expected_exception: Type[BaseException] | tuple[Type[BaseException], ...],
expected_regex: str | bytes | Pattern[str] | Pattern[bytes],
callable: Callable[..., Any],
*args: Any,
@@ -130,20 +129,20 @@ class TestCase:
@overload
def assertRaisesRegex(
self,
expected_exception: Type[_E] | Tuple[Type[_E], ...],
expected_exception: Type[_E] | tuple[Type[_E], ...],
expected_regex: str | bytes | Pattern[str] | Pattern[bytes],
msg: Any = ...,
) -> _AssertRaisesContext[_E]: ...
@overload
def assertWarns( # type: ignore[misc]
self, expected_warning: Type[Warning] | Tuple[Type[Warning], ...], callable: Callable[..., Any], *args: Any, **kwargs: Any
self, expected_warning: Type[Warning] | tuple[Type[Warning], ...], callable: Callable[..., Any], *args: Any, **kwargs: Any
) -> None: ...
@overload
def assertWarns(self, expected_warning: Type[Warning] | Tuple[Type[Warning], ...], msg: Any = ...) -> _AssertWarnsContext: ...
def assertWarns(self, expected_warning: Type[Warning] | tuple[Type[Warning], ...], msg: Any = ...) -> _AssertWarnsContext: ...
@overload
def assertWarnsRegex( # type: ignore[misc]
self,
expected_warning: Type[Warning] | Tuple[Type[Warning], ...],
expected_warning: Type[Warning] | tuple[Type[Warning], ...],
expected_regex: str | bytes | Pattern[str] | Pattern[bytes],
callable: Callable[..., Any],
*args: Any,
@@ -152,7 +151,7 @@ class TestCase:
@overload
def assertWarnsRegex(
self,
expected_warning: Type[Warning] | Tuple[Type[Warning], ...],
expected_warning: Type[Warning] | tuple[Type[Warning], ...],
expected_regex: str | bytes | Pattern[str] | Pattern[bytes],
msg: Any = ...,
) -> _AssertWarnsContext: ...
@@ -200,7 +199,7 @@ class TestCase:
self, seq1: Sequence[Any], seq2: Sequence[Any], msg: Any = ..., seq_type: Type[Sequence[Any]] | None = ...
) -> None: ...
def assertListEqual(self, list1: list[Any], list2: list[Any], msg: Any = ...) -> None: ...
def assertTupleEqual(self, tuple1: Tuple[Any, ...], tuple2: Tuple[Any, ...], msg: Any = ...) -> None: ...
def assertTupleEqual(self, tuple1: tuple[Any, ...], tuple2: tuple[Any, ...], msg: Any = ...) -> None: ...
def assertSetEqual(self, set1: AbstractSet[object], set2: AbstractSet[object], msg: Any = ...) -> None: ...
def assertDictEqual(self, d1: Mapping[Any, object], d2: Mapping[Any, object], msg: Any = ...) -> None: ...
def fail(self, msg: Any = ...) -> NoReturn: ...
@@ -231,13 +230,13 @@ class TestCase:
@overload
def failUnlessRaises( # type: ignore[misc]
self,
exception: Type[BaseException] | Tuple[Type[BaseException], ...],
exception: Type[BaseException] | tuple[Type[BaseException], ...],
callable: Callable[..., Any] = ...,
*args: Any,
**kwargs: Any,
) -> None: ...
@overload
def failUnlessRaises(self, exception: Type[_E] | Tuple[Type[_E], ...], msg: Any = ...) -> _AssertRaisesContext[_E]: ...
def failUnlessRaises(self, exception: Type[_E] | tuple[Type[_E], ...], msg: Any = ...) -> _AssertRaisesContext[_E]: ...
def failUnlessAlmostEqual(self, first: float, second: float, places: int = ..., msg: Any = ...) -> None: ...
def assertAlmostEquals(
self, first: float, second: float, places: int = ..., msg: Any = ..., delta: float = ...
@@ -251,7 +250,7 @@ class TestCase:
@overload
def assertRaisesRegexp( # type: ignore[misc]
self,
exception: Type[BaseException] | Tuple[Type[BaseException], ...],
exception: Type[BaseException] | tuple[Type[BaseException], ...],
expected_regex: str | bytes | Pattern[str] | Pattern[bytes],
callable: Callable[..., Any],
*args: Any,
@@ -260,7 +259,7 @@ class TestCase:
@overload
def assertRaisesRegexp(
self,
exception: Type[_E] | Tuple[Type[_E], ...],
exception: Type[_E] | tuple[Type[_E], ...],
expected_regex: str | bytes | Pattern[str] | Pattern[bytes],
msg: Any = ...,
) -> _AssertRaisesContext[_E]: ...

View File

@@ -3,10 +3,10 @@ import unittest.case
import unittest.result
import unittest.suite
from types import ModuleType
from typing import Any, Callable, List, Pattern, Sequence, Type
from typing import Any, Callable, Pattern, Sequence, Type
_SortComparisonMethod = Callable[[str, str], int]
_SuiteClass = Callable[[List[unittest.case.TestCase]], unittest.suite.TestSuite]
_SuiteClass = Callable[[list[unittest.case.TestCase]], unittest.suite.TestSuite]
VALID_MODULE_NAME: Pattern[str]

View File

@@ -1,5 +1,5 @@
import sys
from typing import Any, Awaitable, Callable, Generic, Iterable, List, Mapping, Sequence, Tuple, Type, TypeVar, overload
from typing import Any, Awaitable, Callable, Generic, Iterable, Mapping, Sequence, Type, TypeVar, overload
_T = TypeVar("_T")
_TT = TypeVar("_TT", bound=Type[Any])
@@ -96,7 +96,7 @@ class _Call(tuple[Any, ...]):
call: _Call
class _CallList(List[_Call]):
class _CallList(list[_Call]):
def __contains__(self, value: Any) -> bool: ...
class Base:
@@ -155,7 +155,7 @@ class NonCallableMock(Base, Any):
call_args_list: _CallList
mock_calls: _CallList
def _format_mock_call_signature(self, args: Any, kwargs: Any) -> str: ...
def _call_matcher(self, _call: Tuple[_Call, ...]) -> _Call: ...
def _call_matcher(self, _call: tuple[_Call, ...]) -> _Call: ...
def _get_child_mock(self, **kw: Any) -> NonCallableMock: ...
class CallableMixin(Base):

View File

@@ -1,8 +1,8 @@
import unittest.case
from types import TracebackType
from typing import Any, Callable, TextIO, Tuple, Type, TypeVar, Union
from typing import Any, Callable, TextIO, Type, TypeVar, Union
_SysExcInfoType = Union[Tuple[Type[BaseException], BaseException, TracebackType], Tuple[None, None, None]]
_SysExcInfoType = Union[tuple[Type[BaseException], BaseException, TracebackType], tuple[None, None, None]]
_F = TypeVar("_F", bound=Callable[..., Any])

View File

@@ -1,7 +1,7 @@
from typing import Any, Sequence, Tuple, TypeVar
from typing import Any, Sequence, TypeVar
_T = TypeVar("_T")
_Mismatch = Tuple[_T, _T, int]
_Mismatch = tuple[_T, _T, int]
_MAX_LENGTH: int
_PLACEHOLDER_LEN: int