|
1 | 1 | import datetime |
2 | 2 |
|
3 | 3 | from types import TracebackType |
4 | | -from typing import \ |
5 | | - Any, Container, Type, Callable, Tuple, Union, ContextManager, \ |
6 | | - Pattern, Optional, Iterable, Text, NoReturn |
| 4 | +from typing import ( |
| 5 | + Any, |
| 6 | + Callable, |
| 7 | + Container, |
| 8 | + ContextManager, |
| 9 | + Generic, |
| 10 | + Iterable, |
| 11 | + NoReturn, |
| 12 | + Optional, |
| 13 | + Pattern, |
| 14 | + Text, |
| 15 | + Tuple, |
| 16 | + Type, |
| 17 | + TypeVar, |
| 18 | + Union, |
| 19 | +) |
7 | 20 |
|
8 | | -class AssertRaisesContext: |
9 | | - exception: Type[BaseException] |
| 21 | +_E = TypeVar("_E", bound=BaseException) |
| 22 | + |
| 23 | +class AssertRaisesContext(Generic[_E]): |
| 24 | + exception: Type[_E] |
10 | 25 | msg_fmt: Text |
11 | | - def __init__(self, exception: Type[BaseException], msg_fmt: Text = ...) -> None: ... |
| 26 | + def __init__(self, exception: Type[_E], msg_fmt: Text = ...) -> None: ... |
12 | 27 | def __enter__(self) -> AssertRaisesContext: ... |
13 | 28 | def __exit__(self, exc_type: Optional[Type[BaseException]], |
14 | 29 | exc_val: Optional[BaseException], |
15 | 30 | exc_tb: Optional[TracebackType]) -> Optional[bool]: ... |
16 | 31 | def format_message(self, default_msg: Text) -> Text: ... |
17 | | - def add_test(self, cb: Callable[[BaseException], None]) -> None: ... |
| 32 | + def add_test(self, cb: Callable[[_E], None]) -> None: ... |
18 | 33 |
|
19 | | -class AssertRaisesErrnoContext(AssertRaisesContext): |
| 34 | +class AssertRaisesErrnoContext(AssertRaisesContext[_E]): |
20 | 35 | expected_errno: int |
21 | | - def __init__(self, exception: Type[BaseException], expected_errno: int, msg_fmt: Text = ...) -> None: ... |
| 36 | + def __init__(self, exception: Type[_E], expected_errno: int, msg_fmt: Text = ...) -> None: ... |
22 | 37 |
|
23 | | -class AssertRaisesRegexContext(AssertRaisesContext): |
| 38 | +class AssertRaisesRegexContext(AssertRaisesContext[_E]): |
24 | 39 | pattern: Text |
25 | | - def __init__(self, exception: Type[BaseException], pattern: Text, msg_fmt: Text = ...) -> None: ... |
| 40 | + def __init__(self, exception: Type[_E], pattern: Text, msg_fmt: Text = ...) -> None: ... |
26 | 41 |
|
27 | 42 | class AssertWarnsContext: |
28 | 43 | def __init__(self, warning_class: Type[Warning], msg_fmt: Text = ...) -> None: ... |
|
0 commit comments