|
1 | 1 | # Stubs for warnings
|
2 | 2 |
|
3 | 3 | import sys
|
4 |
| -from typing import Any, Dict, List, NamedTuple, Optional, overload, TextIO, Tuple, Type, Union, ContextManager |
5 |
| -from types import ModuleType |
| 4 | +from typing import Any, Dict, List, NamedTuple, Optional, overload, TextIO, Tuple, Type, Union |
| 5 | +from types import ModuleType, TracebackType |
6 | 6 |
|
7 | 7 | if sys.version_info >= (3, 8):
|
8 | 8 | from typing import Literal
|
@@ -43,12 +43,20 @@ class _Record(NamedTuple):
|
43 | 43 | file: Optional[TextIO]
|
44 | 44 | line: Optional[str]
|
45 | 45 |
|
46 |
| - |
47 |
| -@overload |
48 |
| -def catch_warnings(*, record: Literal[False] = ..., module: Optional[ModuleType] = ...) -> ContextManager[None]: ... |
49 |
| - |
50 |
| -@overload |
51 |
| -def catch_warnings(*, record: Literal[True], module: Optional[ModuleType] = ...) -> ContextManager[List[_Record]]: ... |
52 |
| - |
53 |
| -@overload |
54 |
| -def catch_warnings(*, record: bool, module: Optional[ModuleType] = ...) -> ContextManager[Optional[List[_Record]]]: ... |
| 46 | +class catch_warnings: |
| 47 | + @overload |
| 48 | + def __new__(cls, *, record: Literal[False] = ..., module: Optional[ModuleType] = ...) -> _catch_warnings_without_records: ... |
| 49 | + @overload |
| 50 | + def __new__(cls, *, record: Literal[True], module: Optional[ModuleType] = ...) -> _catch_warnings_with_records: ... |
| 51 | + @overload |
| 52 | + def __new__(cls, *, record: bool, module: Optional[ModuleType] = ...) -> catch_warnings: ... |
| 53 | + def __enter__(self) -> Optional[List[_Record]]: ... |
| 54 | + def __exit__(self, exc_type: Optional[Type[BaseException]], |
| 55 | + exc_val: Optional[BaseException], |
| 56 | + exc_tb: Optional[TracebackType]) -> None: ... |
| 57 | + |
| 58 | +class _catch_warnings_without_records(catch_warnings): |
| 59 | + def __enter__(self) -> None: ... |
| 60 | + |
| 61 | +class _catch_warnings_with_records(catch_warnings): |
| 62 | + def __enter__(self) -> List[_Record]: ... |
0 commit comments