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:
Brett Cannon 2022-10-05 15:00:45 -07:00 committed by GitHub
parent 2016bc54a2
commit c206e53bb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 45 additions and 102 deletions

View file

@ -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