Skip to content

Commit a8504f2

Browse files
authored
Use _typeshed.OptExcInfo in pydoc and unittest (#7668)
1 parent b093c90 commit a8504f2

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

stdlib/pydoc.pyi

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
from _typeshed import SupportsWrite
1+
from _typeshed import OptExcInfo, SupportsWrite
22
from abc import abstractmethod
33
from builtins import list as _list # "list" conflicts with method name
44
from collections.abc import Callable, Container, Mapping, MutableMapping
55
from reprlib import Repr
66
from types import MethodType, ModuleType, TracebackType
77
from typing import IO, Any, AnyStr, NoReturn, TypeVar
8-
from typing_extensions import TypeAlias
98

109
__all__ = ["help"]
1110

12-
# the return type of sys.exc_info(), used by ErrorDuringImport.__init__
13-
_Exc_Info: TypeAlias = tuple[type[BaseException] | None, BaseException | None, TracebackType | None]
14-
1511
_T = TypeVar("_T")
1612

1713
__author__: str
@@ -39,7 +35,7 @@ class ErrorDuringImport(Exception):
3935
exc: type[BaseException] | None
4036
value: BaseException | None
4137
tb: TracebackType | None
42-
def __init__(self, filename: str, exc_info: _Exc_Info) -> None: ...
38+
def __init__(self, filename: str, exc_info: OptExcInfo) -> None: ...
4339

4440
def importfile(path: str) -> ModuleType: ...
4541
def safeimport(path: str, forceload: bool = ..., cache: MutableMapping[str, ModuleType] = ...) -> ModuleType: ...

stdlib/unittest/result.pyi

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import unittest.case
2+
from _typeshed import OptExcInfo
23
from collections.abc import Callable
3-
from types import TracebackType
4-
from typing import Any, TextIO, TypeVar, Union
5-
from typing_extensions import TypeAlias
6-
7-
_SysExcInfoType: TypeAlias = Union[tuple[type[BaseException], BaseException, TracebackType], tuple[None, None, None]]
4+
from typing import Any, TextIO, TypeVar
85

96
_F = TypeVar("_F", bound=Callable[..., Any])
107

@@ -33,10 +30,10 @@ class TestResult:
3330
def stopTest(self, test: unittest.case.TestCase) -> None: ...
3431
def startTestRun(self) -> None: ...
3532
def stopTestRun(self) -> None: ...
36-
def addError(self, test: unittest.case.TestCase, err: _SysExcInfoType) -> None: ...
37-
def addFailure(self, test: unittest.case.TestCase, err: _SysExcInfoType) -> None: ...
33+
def addError(self, test: unittest.case.TestCase, err: OptExcInfo) -> None: ...
34+
def addFailure(self, test: unittest.case.TestCase, err: OptExcInfo) -> None: ...
3835
def addSuccess(self, test: unittest.case.TestCase) -> None: ...
3936
def addSkip(self, test: unittest.case.TestCase, reason: str) -> None: ...
40-
def addExpectedFailure(self, test: unittest.case.TestCase, err: _SysExcInfoType) -> None: ...
37+
def addExpectedFailure(self, test: unittest.case.TestCase, err: OptExcInfo) -> None: ...
4138
def addUnexpectedSuccess(self, test: unittest.case.TestCase) -> None: ...
42-
def addSubTest(self, test: unittest.case.TestCase, subtest: unittest.case.TestCase, err: _SysExcInfoType | None) -> None: ...
39+
def addSubTest(self, test: unittest.case.TestCase, subtest: unittest.case.TestCase, err: OptExcInfo | None) -> None: ...

0 commit comments

Comments
 (0)