mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
Issue #14938: importlib.abc.SourceLoader.is_package() now takes the
module name into consideration when determining whether a module is a package or not. This prevents importing a module's __init__ module directly and having it considered a package, which can lead to duplicate sub-modules. Thanks to Ronan Lamy for reporting the bug.
This commit is contained in:
parent
0450c9ed52
commit
ea0b823940
4 changed files with 14 additions and 5 deletions
|
@ -578,7 +578,9 @@ class _LoaderBasics:
|
|||
"""Concrete implementation of InspectLoader.is_package by checking if
|
||||
the path returned by get_filename has a filename of '__init__.py'."""
|
||||
filename = _path_split(self.get_filename(fullname))[1]
|
||||
return filename.rsplit('.', 1)[0] == '__init__'
|
||||
filename_base = filename.rsplit('.', 1)[0]
|
||||
tail_name = fullname.rpartition('.')[2]
|
||||
return filename_base == '__init__' and tail_name != '__init__'
|
||||
|
||||
def _bytes_from_bytecode(self, fullname, data, bytecode_path, source_stats):
|
||||
"""Return the marshalled bytes from bytecode, verifying the magic
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue