Skip to content

Commit

Permalink
Defer importing warnings in several modules
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Oct 3, 2023
1 parent 0b5f5b0 commit 0913bf0
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Lib/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from enum import IntEnum, global_enum
import locale as _locale
from itertools import repeat
import warnings

__all__ = ["IllegalMonthError", "IllegalWeekdayError", "setfirstweekday",
"firstweekday", "isleap", "leapdays", "weekday", "monthrange",
Expand Down Expand Up @@ -44,6 +43,7 @@ def __str__(self):

def __getattr__(name):
if name in ('January', 'February'):
import warnings
warnings.warn(f"The '{name}' attribute is deprecated, use '{name.upper()}' instead",
DeprecationWarning, stacklevel=2)
if name == 'January':
Expand Down
2 changes: 1 addition & 1 deletion Lib/getpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io
import os
import sys
import warnings

__all__ = ["getpass","getuser","GetPassWarning"]

Expand Down Expand Up @@ -118,6 +117,7 @@ def win_getpass(prompt='Password: ', stream=None):


def fallback_getpass(prompt='Password: ', stream=None):
import warnings
warnings.warn("Can not control echo on the terminal.", GetPassWarning,
stacklevel=2)
if not stream:
Expand Down
3 changes: 2 additions & 1 deletion Lib/pkgutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import os.path
import sys
from types import ModuleType
import warnings

__all__ = [
'get_importer', 'iter_importers', 'get_loader', 'find_loader',
Expand Down Expand Up @@ -270,6 +269,7 @@ def get_loader(module_or_name):
If the named module is not already imported, its containing package
(if any) is imported, in order to establish the package __path__.
"""
import warnings
warnings._deprecated("pkgutil.get_loader",
f"{warnings._DEPRECATED_MSG}; "
"use importlib.util.find_spec() instead",
Expand Down Expand Up @@ -298,6 +298,7 @@ def find_loader(fullname):
importlib.util.find_spec that converts most failures to ImportError
and only returns the loader rather than the full spec
"""
import warnings
warnings._deprecated("pkgutil.find_loader",
f"{warnings._DEPRECATED_MSG}; "
"use importlib.util.find_spec() instead",
Expand Down
2 changes: 1 addition & 1 deletion Lib/shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import fnmatch
import collections
import errno
import warnings

try:
import zlib
Expand Down Expand Up @@ -723,6 +722,7 @@ def rmtree(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None):
"""

if onerror is not None:
import warnings
warnings.warn("onerror argument is deprecated, use onexc instead",
DeprecationWarning, stacklevel=2)

Expand Down
2 changes: 1 addition & 1 deletion Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import struct
import copy
import re
import warnings

try:
import pwd
Expand Down Expand Up @@ -2219,6 +2218,7 @@ def _get_filter_function(self, filter):
if filter is None:
filter = self.extraction_filter
if filter is None:
import warnings
warnings.warn(
'Python 3.14 will, by default, filter extracted tar '
+ 'archives and reject files or modify their metadata. '
Expand Down

0 comments on commit 0913bf0

Please sign in to comment.