| 1 |
import re |
| 2 |
import sys |
| 3 |
from _warnings import warn as warn, warn_explicit as warn_explicit |
| 4 |
from collections.abc import Sequence |
| 5 |
from types import ModuleType, TracebackType |
| 6 |
from typing import Any, Generic, Literal, TextIO, overload |
| 7 |
from typing_extensions import LiteralString, TypeAlias, TypeVar |
| 8 |
|
| 9 |
__all__ = [ |
| 10 |
"warn", |
| 11 |
"warn_explicit", |
| 12 |
"showwarning", |
| 13 |
"formatwarning", |
| 14 |
"filterwarnings", |
| 15 |
"simplefilter", |
| 16 |
"resetwarnings", |
| 17 |
"catch_warnings", |
| 18 |
] |
| 19 |
|
| 20 |
if sys.version_info >= (3, 13): |
| 21 |
__all__ += ["deprecated"] |
| 22 |
|
| 23 |
_T = TypeVar("_T") |
| 24 |
_W_co = TypeVar("_W_co", bound=list[WarningMessage] | None, default=list[WarningMessage] | None, covariant=True) |
| 25 |
|
| 26 |
if sys.version_info >= (3, 14): |
| 27 |
_ActionKind: TypeAlias = Literal["default", "error", "ignore", "always", "module", "once"] |
| 28 |
else: |
| 29 |
_ActionKind: TypeAlias = Literal["default", "error", "ignore", "always", "all", "module", "once"] |
| 30 |
filters: Sequence[tuple[str, re.Pattern[str] | None, type[Warning], re.Pattern[str] | None, int]] |
| 31 |
|
| 32 |
def showwarning( |
| 33 |
message: Warning | str, |
| 34 |
category: type[Warning], |
| 35 |
filename: str, |
| 36 |
lineno: int, |
| 37 |
file: TextIO | None = None, |
| 38 |
line: str | None = None, |
| 39 |
) -> None: ... |
| 40 |
def formatwarning( |
| 41 |
message: Warning | str, category: type[Warning], filename: str, lineno: int, line: str | None = None |
| 42 |
) -> str: ... |
| 43 |
def filterwarnings( |
| 44 |
action: _ActionKind, message: str = "", category: type[Warning] = ..., module: str = "", lineno: int = 0, append: bool = False |
| 45 |
) -> None: ... |
| 46 |
def simplefilter(action: _ActionKind, category: type[Warning] = ..., lineno: int = 0, append: bool = False) -> None: ... |
| 47 |
def resetwarnings() -> None: ... |
| 48 |
|
| 49 |
class _OptionError(Exception): ... |
| 50 |
|
| 51 |
class WarningMessage: |
| 52 |
message: Warning | str |
| 53 |
category: type[Warning] |
| 54 |
filename: str |
| 55 |
lineno: int |
| 56 |
file: TextIO | None |
| 57 |
line: str | None |
| 58 |
source: Any | None |
| 59 |
def __init__( |
| 60 |
self, |
| 61 |
message: Warning | str, |
| 62 |
category: type[Warning], |
| 63 |
filename: str, |
| 64 |
lineno: int, |
| 65 |
file: TextIO | None = None, |
| 66 |
line: str | None = None, |
| 67 |
source: Any | None = None, |
| 68 |
) -> None: ... |
| 69 |
|
| 70 |
class catch_warnings(Generic[_W_co]): |
| 71 |
if sys.version_info >= (3, 11): |
| 72 |
@overload |
| 73 |
def __init__( |
| 74 |
self: catch_warnings[None], |
| 75 |
*, |
| 76 |
record: Literal[False] = False, |
| 77 |
module: ModuleType | None = None, |
| 78 |
action: _ActionKind | None = None, |
| 79 |
category: type[Warning] = ..., |
| 80 |
lineno: int = 0, |
| 81 |
append: bool = False, |
| 82 |
) -> None: ... |
| 83 |
@overload |
| 84 |
def __init__( |
| 85 |
self: catch_warnings[list[WarningMessage]], |
| 86 |
*, |
| 87 |
record: Literal[True], |
| 88 |
module: ModuleType | None = None, |
| 89 |
action: _ActionKind | None = None, |
| 90 |
category: type[Warning] = ..., |
| 91 |
lineno: int = 0, |
| 92 |
append: bool = False, |
| 93 |
) -> None: ... |
| 94 |
@overload |
| 95 |
def __init__( |
| 96 |
self, |
| 97 |
*, |
| 98 |
record: bool, |
| 99 |
module: ModuleType | None = None, |
| 100 |
action: _ActionKind | None = None, |
| 101 |
category: type[Warning] = ..., |
| 102 |
lineno: int = 0, |
| 103 |
append: bool = False, |
| 104 |
) -> None: ... |
| 105 |
else: |
| 106 |
@overload |
| 107 |
def __init__(self: catch_warnings[None], *, record: Literal[False] = False, module: ModuleType | None = None) -> None: ... |
| 108 |
@overload |
| 109 |
def __init__( |
| 110 |
self: catch_warnings[list[WarningMessage]], *, record: Literal[True], module: ModuleType | None = None |
| 111 |
) -> None: ... |
| 112 |
@overload |
| 113 |
def __init__(self, *, record: bool, module: ModuleType | None = None) -> None: ... |
| 114 |
|
| 115 |
def __enter__(self) -> _W_co: ... |
| 116 |
def __exit__( |
| 117 |
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None |
| 118 |
) -> None: ... |
| 119 |
|
| 120 |
if sys.version_info >= (3, 13): |
| 121 |
class deprecated: |
| 122 |
message: LiteralString |
| 123 |
category: type[Warning] | None |
| 124 |
stacklevel: int |
| 125 |
def __init__(self, message: LiteralString, /, *, category: type[Warning] | None = ..., stacklevel: int = 1) -> None: ... |
| 126 |
def __call__(self, arg: _T, /) -> _T: ... |