Skip to content

warnings: New arguments to catch_warnings() #7685

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 3 commits into from
Apr 26, 2022
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
49 changes: 43 additions & 6 deletions stdlib/warnings.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from _warnings import warn as warn, warn_explicit as warn_explicit
from collections.abc import Sequence
from types import ModuleType, TracebackType
Expand Down Expand Up @@ -56,12 +57,48 @@ class WarningMessage:
) -> None: ...

class catch_warnings:
@overload
def __new__(cls, *, record: Literal[False] = ..., module: ModuleType | None = ...) -> _catch_warnings_without_records: ...
@overload
def __new__(cls, *, record: Literal[True], module: ModuleType | None = ...) -> _catch_warnings_with_records: ...
@overload
def __new__(cls, *, record: bool, module: ModuleType | None = ...) -> catch_warnings: ...
if sys.version_info >= (3, 11):
@overload
def __new__(
cls,
*,
record: Literal[False] = ...,
module: ModuleType | None = ...,
action: _ActionKind | None = ...,
category: type[Warning] = ...,
lineno: int = ...,
append: bool = ...,
) -> _catch_warnings_without_records: ...
@overload
def __new__(
cls,
*,
record: Literal[True],
module: ModuleType | None = ...,
action: _ActionKind | None = ...,
category: type[Warning] = ...,
lineno: int = ...,
append: bool = ...,
) -> _catch_warnings_with_records: ...
@overload
def __new__(
cls,
*,
record: bool,
module: ModuleType | None = ...,
action: _ActionKind | None = ...,
category: type[Warning] = ...,
lineno: int = ...,
append: bool = ...,
) -> catch_warnings: ...
else:
@overload
def __new__(cls, *, record: Literal[False] = ..., module: ModuleType | None = ...) -> _catch_warnings_without_records: ...
@overload
def __new__(cls, *, record: Literal[True], module: ModuleType | None = ...) -> _catch_warnings_with_records: ...
@overload
def __new__(cls, *, record: bool, module: ModuleType | None = ...) -> catch_warnings: ...

def __enter__(self) -> list[WarningMessage] | None: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
Expand Down