Skip to content

Import of submodule shadowing parent module attribute fails under lazy_imports mode #151208

@jacobtylerwalls

Description

@jacobtylerwalls

Bug report

Bug description:

For this module structure:

└─ a/
   ├─ __init__.py    # Contains a function foo()
   └─ foo.py

This script passes on 3.14...

from a import foo
import a.foo
import types
assert isinstance(a.foo, types.ModuleType), type(a.foo)

And fails on 3.15 with lazy imports (python3.15 -X lazy_imports=all script.py):

Traceback (most recent call last):
  File "/Users/jwalls/script.py", line 4, in <module>
    assert isinstance(a.foo, types.ModuleType), type(a.foo)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: <class 'function'>

CPython versions tested on:

3.15

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions