unittest: Use a recursive type alias for assertIsInstance (#9770)

This commit is contained in:
Alex Waygood
2023-02-20 15:35:50 +00:00
committed by GitHub
parent 5e6b172e17
commit 4273a83bb7
2 changed files with 8 additions and 4 deletions

View File

@@ -68,10 +68,13 @@ class SkipTest(Exception):
class _SupportsAbsAndDunderGE(SupportsDunderGE[Any], SupportsAbs[Any], Protocol): ...
# Keep this alias in sync with builtins._ClassInfo
# We can't import it from builtins or pytype crashes,
# due to the fact that pytype uses a custom builtins stub rather than typeshed's builtins stub
if sys.version_info >= (3, 10):
_IsInstanceClassInfo: TypeAlias = type | UnionType | tuple[type | UnionType | tuple[Any, ...], ...]
_ClassInfo: TypeAlias = type | UnionType | tuple[_ClassInfo, ...]
else:
_IsInstanceClassInfo: TypeAlias = type | tuple[type | tuple[Any, ...], ...]
_ClassInfo: TypeAlias = type | tuple[_ClassInfo, ...]
class TestCase:
failureException: type[BaseException]
@@ -107,8 +110,8 @@ class TestCase:
def assertIsNotNone(self, obj: object, msg: Any = None) -> None: ...
def assertIn(self, member: Any, container: Iterable[Any] | Container[Any], msg: Any = None) -> None: ...
def assertNotIn(self, member: Any, container: Iterable[Any] | Container[Any], msg: Any = None) -> None: ...
def assertIsInstance(self, obj: object, cls: _IsInstanceClassInfo, msg: Any = None) -> None: ...
def assertNotIsInstance(self, obj: object, cls: _IsInstanceClassInfo, msg: Any = None) -> None: ...
def assertIsInstance(self, obj: object, cls: _ClassInfo, msg: Any = None) -> None: ...
def assertNotIsInstance(self, obj: object, cls: _ClassInfo, msg: Any = None) -> None: ...
@overload
def assertGreater(self, a: SupportsDunderGT[_T], b: _T, msg: Any = None) -> None: ...
@overload