mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Move importlib's frozen importer over to rpartition for setting __package__.
This commit is contained in:
parent
2b3849425f
commit
eb2e0dd19d
2 changed files with 4 additions and 5 deletions
|
@ -138,10 +138,9 @@ class FrozenImporter:
|
|||
if cls.find_module(fullname) is None:
|
||||
raise ImportError("{0} is not a frozen module".format(fullname))
|
||||
module = imp.init_frozen(fullname)
|
||||
if hasattr(module, '__path__'):
|
||||
module.__package__ = module.__name__
|
||||
elif '.' in module.__name__:
|
||||
module.__package__ = module.__name__.rsplit('.', 1)[0]
|
||||
if not hasattr(module, '__path__'):
|
||||
module.__package__ = module.__package__.rpartition('.')[0]
|
||||
return module
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class LoaderTests(abc.LoaderTests):
|
|||
with util.uncache('__hello__'):
|
||||
module = machinery.FrozenImporter.load_module('__hello__')
|
||||
check = {'__name__': '__hello__', '__file__': '<frozen>',
|
||||
'__package__': None}
|
||||
'__package__': ''}
|
||||
for attr, value in check.items():
|
||||
self.assertEqual(getattr(module, attr), value)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue