summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2022-10-05 22:00:45 (GMT)
committerGitHub <noreply@github.com>2022-10-05 22:00:45 (GMT)
commitc206e53bb726fa795d10cfb0e8d1d1a1a5d1aaa7 (patch)
tree137f9ccf92283c7d33da6f7cf2b614ebcb9ea2c1 /Lib/importlib
parent2016bc54a22b83d0ca9174b64257cc7bb67a0916 (diff)
downloadcpython-c206e53bb726fa795d10cfb0e8d1d1a1a5d1aaa7.zip
cpython-c206e53bb726fa795d10cfb0e8d1d1a1a5d1aaa7.tar.gz
cpython-c206e53bb726fa795d10cfb0e8d1d1a1a5d1aaa7.tar.bz2
gh-65961: Raise `DeprecationWarning` when `__package__` differs from `__spec__.parent` (#97879)
Also remove `importlib.util.set_package()` which was already slated for removal. Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py2
-rw-r--r--Lib/importlib/util.py20
2 files changed, 1 insertions, 21 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 5d3c9fe..1c13210 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -1228,7 +1228,7 @@ def _calc___package__(globals):
if spec is not None and package != spec.parent:
_warnings.warn("__package__ != __spec__.parent "
f"({package!r} != {spec.parent!r})",
- ImportWarning, stacklevel=3)
+ DeprecationWarning, stacklevel=3)
return package
elif spec is not None:
return spec.parent
diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py
index 8623c89..7f15b02 100644
--- a/Lib/importlib/util.py
+++ b/Lib/importlib/util.py
@@ -141,26 +141,6 @@ def _module_to_load(name):
module.__initializing__ = False
-def set_package(fxn):
- """Set __package__ on the returned module.
-
- This function is deprecated.
-
- """
- @functools.wraps(fxn)
- def set_package_wrapper(*args, **kwargs):
- warnings.warn('The import system now takes care of this automatically; '
- 'this decorator is slated for removal in Python 3.12',
- DeprecationWarning, stacklevel=2)
- module = fxn(*args, **kwargs)
- if getattr(module, '__package__', None) is None:
- module.__package__ = module.__name__
- if not hasattr(module, '__path__'):
- module.__package__ = module.__package__.rpartition('.')[0]
- return module
- return set_package_wrapper
-
-
def set_loader(fxn):
"""Set __loader__ on the returned module.