Skip to content

Refactor warnings.catch_warning to be a class. #3499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions stdlib/2and3/warnings.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Stubs for warnings

import sys
from typing import Any, Dict, List, NamedTuple, Optional, overload, TextIO, Tuple, Type, Union, ContextManager
from types import ModuleType
from typing import Any, Dict, List, NamedTuple, Optional, overload, TextIO, Tuple, Type, Union
from types import ModuleType, TracebackType

if sys.version_info >= (3, 8):
from typing import Literal
Expand Down Expand Up @@ -43,12 +43,20 @@ class _Record(NamedTuple):
file: Optional[TextIO]
line: Optional[str]


@overload
def catch_warnings(*, record: Literal[False] = ..., module: Optional[ModuleType] = ...) -> ContextManager[None]: ...

@overload
def catch_warnings(*, record: Literal[True], module: Optional[ModuleType] = ...) -> ContextManager[List[_Record]]: ...

@overload
def catch_warnings(*, record: bool, module: Optional[ModuleType] = ...) -> ContextManager[Optional[List[_Record]]]: ...
class catch_warnings:
@overload
def __new__(cls, *, record: Literal[False] = ..., module: Optional[ModuleType] = ...) -> _catch_warnings_without_records: ...
@overload
def __new__(cls, *, record: Literal[True], module: Optional[ModuleType] = ...) -> _catch_warnings_with_records: ...
@overload
def __new__(cls, *, record: bool, module: Optional[ModuleType] = ...) -> catch_warnings: ...
def __enter__(self) -> Optional[List[_Record]]: ...
def __exit__(self, exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType]) -> None: ...

class _catch_warnings_without_records(catch_warnings):
def __enter__(self) -> None: ...

class _catch_warnings_with_records(catch_warnings):
def __enter__(self) -> List[_Record]: ...