From a7d24b2ad570fdd4c03590bd775f009af2d23e40 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 23 Mar 2021 00:00:03 +0100 Subject: [PATCH] bpo-41718: importlib no longer imports warnings at startup The importlib module no longer imports warnings at startup, but only imports it when a deprecated function is called. --- Lib/importlib/__init__.py | 3 +-- Lib/importlib/util.py | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index 03ff71489abbd60..657142387dc5378 100644 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -54,8 +54,6 @@ # Fully bootstrapped at this point, import whatever you like, circular # dependencies and startup overhead minimisation permitting :) -import warnings - # Public API ######################################################### @@ -78,6 +76,7 @@ def find_loader(name, path=None): This function is deprecated in favor of importlib.util.find_spec(). """ + import warnings warnings.warn('Deprecated since Python 3.4. ' 'Use importlib.util.find_spec() instead.', DeprecationWarning, stacklevel=2) diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py index 98a0fa54dfd873e..e36ec32838ffc0d 100644 --- a/Lib/importlib/util.py +++ b/Lib/importlib/util.py @@ -16,7 +16,6 @@ import functools import sys import types -import warnings def source_hash(source_bytes): @@ -149,6 +148,7 @@ def set_package(fxn): """ @functools.wraps(fxn) def set_package_wrapper(*args, **kwargs): + import warnings warnings.warn('The import system now takes care of this automatically.', DeprecationWarning, stacklevel=2) module = fxn(*args, **kwargs) @@ -168,6 +168,7 @@ def set_loader(fxn): """ @functools.wraps(fxn) def set_loader_wrapper(self, *args, **kwargs): + import warnings warnings.warn('The import system now takes care of this automatically.', DeprecationWarning, stacklevel=2) module = fxn(self, *args, **kwargs) @@ -195,6 +196,7 @@ def module_for_loader(fxn): the second argument. """ + import warnings warnings.warn('The import system now takes care of this automatically.', DeprecationWarning, stacklevel=2) @functools.wraps(fxn)