mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
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>
This commit is contained in:
parent
2016bc54a2
commit
c206e53bb7
9 changed files with 45 additions and 102 deletions
|
@ -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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue