Skip to content

Getting ImportError and suggestion to rename module for no valid reason #136094

Open
@sausix

Description

@sausix

Bug report

Bug description:

I can't trigger the classic "partially initialized module" ImportError anymore.
Circular imports are a different issue and not related to shadowing one of sys.stdlib_module_names for example.

# mainmod.py
from secondmod import secondaryitem

mainitem = 1
# secondmod.py
from mainmod import mainitem

secondaryitem = 2

I made sure there is no package installed providing mainmod or secondmod.

In Python 3.13.5:

# python3 mainmod.py

Traceback (most recent call last):
  File "/home/as/mainmod.py", line 1, in <module>
    from secondmod import secondaryitem
  File "/home/as/secondmod.py", line 1, in <module>
    from mainmod import mainitem
  File "/home/as/mainmod.py", line 1, in <module>
    from secondmod import secondaryitem
ImportError: cannot import name 'secondaryitem' from 'secondmod' (consider renaming '/home/as/secondmod.py' if it has the same name as a library you intended to import)

Before in Python 3.12.6:

python3 mainmod.py

Traceback (most recent call last):
  File "/home/as/mainmod.py", line 1, in <module>
    from secondmod import secondaryitem
  File "/home/as/secondmod.py", line 1, in <module>
    from mainmod import mainitem
  File "/home/as/mainmod.py", line 1, in <module>
    from secondmod import secondaryitem
ImportError: cannot import name 'secondaryitem' from partially initialized module 'secondmod' (most likely due to a circular import) (/home/as/secondmod.py)

Because it's an improvement mostly for beginners, the warning should appear only when colliding with sys.stdlib_module_names or maybe other installed third party packages. It should not trigger for modules of the same project.

I've read the threads about this new Python 3.13 feature and could not find any report on this false positive warning.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions