mirror of https://github.com/python/cpython
gh-109653: Defer importing `warnings` in several modules (#110286)
This commit is contained in:
parent
f02f26e293
commit
bfe7e72522
|
@ -89,8 +89,6 @@ import os as _os
|
||||||
import re as _re
|
import re as _re
|
||||||
import sys as _sys
|
import sys as _sys
|
||||||
|
|
||||||
import warnings
|
|
||||||
|
|
||||||
from gettext import gettext as _, ngettext
|
from gettext import gettext as _, ngettext
|
||||||
|
|
||||||
SUPPRESS = '==SUPPRESS=='
|
SUPPRESS = '==SUPPRESS=='
|
||||||
|
@ -910,6 +908,7 @@ class BooleanOptionalAction(Action):
|
||||||
# parser.add_argument('-f', action=BooleanOptionalAction, type=int)
|
# parser.add_argument('-f', action=BooleanOptionalAction, type=int)
|
||||||
for field_name in ('type', 'choices', 'metavar'):
|
for field_name in ('type', 'choices', 'metavar'):
|
||||||
if locals()[field_name] is not _deprecated_default:
|
if locals()[field_name] is not _deprecated_default:
|
||||||
|
import warnings
|
||||||
warnings._deprecated(
|
warnings._deprecated(
|
||||||
field_name,
|
field_name,
|
||||||
"{name!r} is deprecated as of Python 3.12 and will be "
|
"{name!r} is deprecated as of Python 3.12 and will be "
|
||||||
|
@ -1700,6 +1699,7 @@ class _ArgumentGroup(_ActionsContainer):
|
||||||
self._group_actions.remove(action)
|
self._group_actions.remove(action)
|
||||||
|
|
||||||
def add_argument_group(self, *args, **kwargs):
|
def add_argument_group(self, *args, **kwargs):
|
||||||
|
import warnings
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"Nesting argument groups is deprecated.",
|
"Nesting argument groups is deprecated.",
|
||||||
category=DeprecationWarning,
|
category=DeprecationWarning,
|
||||||
|
@ -1728,6 +1728,7 @@ class _MutuallyExclusiveGroup(_ArgumentGroup):
|
||||||
self._group_actions.remove(action)
|
self._group_actions.remove(action)
|
||||||
|
|
||||||
def add_mutually_exclusive_group(self, *args, **kwargs):
|
def add_mutually_exclusive_group(self, *args, **kwargs):
|
||||||
|
import warnings
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"Nesting mutually exclusive groups is deprecated.",
|
"Nesting mutually exclusive groups is deprecated.",
|
||||||
category=DeprecationWarning,
|
category=DeprecationWarning,
|
||||||
|
|
|
@ -10,7 +10,6 @@ import datetime
|
||||||
from enum import IntEnum, global_enum
|
from enum import IntEnum, global_enum
|
||||||
import locale as _locale
|
import locale as _locale
|
||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
import warnings
|
|
||||||
|
|
||||||
__all__ = ["IllegalMonthError", "IllegalWeekdayError", "setfirstweekday",
|
__all__ = ["IllegalMonthError", "IllegalWeekdayError", "setfirstweekday",
|
||||||
"firstweekday", "isleap", "leapdays", "weekday", "monthrange",
|
"firstweekday", "isleap", "leapdays", "weekday", "monthrange",
|
||||||
|
@ -44,6 +43,7 @@ class IllegalWeekdayError(ValueError):
|
||||||
|
|
||||||
def __getattr__(name):
|
def __getattr__(name):
|
||||||
if name in ('January', 'February'):
|
if name in ('January', 'February'):
|
||||||
|
import warnings
|
||||||
warnings.warn(f"The '{name}' attribute is deprecated, use '{name.upper()}' instead",
|
warnings.warn(f"The '{name}' attribute is deprecated, use '{name.upper()}' instead",
|
||||||
DeprecationWarning, stacklevel=2)
|
DeprecationWarning, stacklevel=2)
|
||||||
if name == 'January':
|
if name == 'January':
|
||||||
|
|
|
@ -18,7 +18,6 @@ import contextlib
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
|
||||||
|
|
||||||
__all__ = ["getpass","getuser","GetPassWarning"]
|
__all__ = ["getpass","getuser","GetPassWarning"]
|
||||||
|
|
||||||
|
@ -118,6 +117,7 @@ def win_getpass(prompt='Password: ', stream=None):
|
||||||
|
|
||||||
|
|
||||||
def fallback_getpass(prompt='Password: ', stream=None):
|
def fallback_getpass(prompt='Password: ', stream=None):
|
||||||
|
import warnings
|
||||||
warnings.warn("Can not control echo on the terminal.", GetPassWarning,
|
warnings.warn("Can not control echo on the terminal.", GetPassWarning,
|
||||||
stacklevel=2)
|
stacklevel=2)
|
||||||
if not stream:
|
if not stream:
|
||||||
|
|
|
@ -10,7 +10,6 @@ import stat
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import collections
|
import collections
|
||||||
import errno
|
import errno
|
||||||
import warnings
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import zlib
|
import zlib
|
||||||
|
@ -723,6 +722,7 @@ def rmtree(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if onerror is not None:
|
if onerror is not None:
|
||||||
|
import warnings
|
||||||
warnings.warn("onerror argument is deprecated, use onexc instead",
|
warnings.warn("onerror argument is deprecated, use onexc instead",
|
||||||
DeprecationWarning, stacklevel=2)
|
DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,6 @@ import time
|
||||||
import struct
|
import struct
|
||||||
import copy
|
import copy
|
||||||
import re
|
import re
|
||||||
import warnings
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pwd
|
import pwd
|
||||||
|
@ -2219,6 +2218,7 @@ class TarFile(object):
|
||||||
if filter is None:
|
if filter is None:
|
||||||
filter = self.extraction_filter
|
filter = self.extraction_filter
|
||||||
if filter is None:
|
if filter is None:
|
||||||
|
import warnings
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
'Python 3.14 will, by default, filter extracted tar '
|
'Python 3.14 will, by default, filter extracted tar '
|
||||||
+ 'archives and reject files or modify their metadata. '
|
+ 'archives and reject files or modify their metadata. '
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Slightly improve the import time of several standard-library modules by
|
||||||
|
deferring imports of :mod:`warnings` within those modules. Patch by Alex
|
||||||
|
Waygood.
|
Loading…
Reference in New Issue