Skip to content

Commit dba89e0

Browse files
committed
Add warnings.py module (missed in previous commit).
1 parent 1c02b7e commit dba89e0

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

Lib/warnings.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import sys
2+
3+
__all__ = [
4+
"warn",
5+
"warn_explicit",
6+
"showwarning",
7+
"formatwarning",
8+
"filterwarnings",
9+
"simplefilter",
10+
"resetwarnings",
11+
"catch_warnings",
12+
"deprecated",
13+
]
14+
15+
from _py_warnings import (
16+
WarningMessage,
17+
_DEPRECATED_MSG,
18+
_OptionError,
19+
_add_filter,
20+
_deprecated,
21+
_filters_mutated,
22+
_filters_mutated_lock_held,
23+
_filters_version,
24+
_formatwarning_orig,
25+
_formatwarnmsg,
26+
_formatwarnmsg_impl,
27+
_get_context,
28+
_get_filters,
29+
_getaction,
30+
_getcategory,
31+
_is_filename_to_skip,
32+
_is_internal_filename,
33+
_is_internal_frame,
34+
_lock,
35+
_new_context,
36+
_next_external_frame,
37+
_processoptions,
38+
_set_context,
39+
_set_module,
40+
_setoption,
41+
_setup_defaults,
42+
_showwarning_orig,
43+
_showwarnmsg,
44+
_showwarnmsg_impl,
45+
_use_context,
46+
_warn_unawaited_coroutine,
47+
_warnings_context,
48+
catch_warnings,
49+
defaultaction,
50+
deprecated,
51+
filters,
52+
filterwarnings,
53+
formatwarning,
54+
onceregistry,
55+
resetwarnings,
56+
showwarning,
57+
simplefilter,
58+
warn,
59+
warn_explicit,
60+
)
61+
62+
try:
63+
# Try to use the C extension, this will replace some parts of the
64+
# _py_warnings implementation imported above.
65+
from _warnings import (
66+
_acquire_lock,
67+
_defaultaction as defaultaction,
68+
_filters_mutated_lock_held,
69+
_onceregistry as onceregistry,
70+
_release_lock,
71+
_warnings_context,
72+
filters,
73+
warn,
74+
warn_explicit,
75+
)
76+
77+
_warnings_defaults = True
78+
79+
class _Lock:
80+
def __enter__(self):
81+
_acquire_lock()
82+
return self
83+
84+
def __exit__(self, *args):
85+
_release_lock()
86+
87+
_lock = _Lock()
88+
except ImportError:
89+
_warnings_defaults = False
90+
91+
92+
# Module initialization
93+
_set_module(sys.modules[__name__])
94+
_processoptions(sys.warnoptions)
95+
if not _warnings_defaults:
96+
_setup_defaults()
97+
98+
del _warnings_defaults
99+
del _setup_defaults

0 commit comments

Comments
 (0)