GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Getting ImportError and suggestion to rename module for no valid reason · Issue #136094 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Getting ImportError and suggestion to rename module for no valid reason#136094
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@sausix
sausix
opened on Jun 29, 2025
Issue body actions

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

Activity

  1. sausix
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jun 29, 2025
  2. hugovk commented on Jun 29, 2025

    @hugovk
    hugovk
    on Jun 29, 2025
    Member
    More actions

    Hello, this is the issue tracker for the Python language itself.

    Please open a topic in the help forum to ask about your own code:

    https://discuss.python.org/c/help/7

  3. hugovk
    closed this as not plannedon Jun 29, 2025
  4. sausix commented on Jun 29, 2025

    @sausix
    sausix
    on Jun 29, 2025
    Author
    More actions

    I know the difference between Python and CPython.

    And it's an issue/change in CPython. It's not about my own code.

    Reacted by BrenBarn
  5. hugovk commented on Jun 29, 2025

    @hugovk
    hugovk
    on Jun 29, 2025
    Member
    More actions

    One of these changes was from #112577, cc @hauntsaninja.

  6. hugovk
    reopened this on Jun 29, 2025
  7. StanFromIreland
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Jun 29, 2025
  8. brianschubert commented on Jun 29, 2025

    @brianschubert
    brianschubert
    on Jun 29, 2025
    Contributor
    More actions

    For reference, the "consider renaming" error was introduced by #113769

  9. hauntsaninja commented on Jun 29, 2025

    @hauntsaninja
    hauntsaninja
    on Jun 29, 2025
    Contributor
    More actions

    Thanks for the issue!

    There are actually two separate warnings we issue, one for the standard library case and one for the potential third party case:

    • The standard library one checks against sys.stdlib_module_names as you suggest, and the error message is something like: AttributeError: module 'random' has no attribute 'randint' (consider renaming '/home/me/random.py' since it has the same name as the standard library module named 'random' and prevents importing that standard library module)

    • The potential third party case message is something like: AttributeError: module 'numpy' has no attribute 'array' (consider renaming '/home/me/numpy.py' if it has the same name as a library you intended to import)

    Two notes:

    • There are plenty of cases where we preserve the error message for circular imports as they were on Python 3.12 , see here
    • The message used to say "if it has the same name as a third-party module" instead of "library", but Pablo asked for the change in: gh-123930: Better error for "from imports" when script shadows module #123929 (comment)

    Here are the things I'm solving for:

    • I would like to issue some "consider renaming" message in the third party shadowing case
      • In my experience / from forums, it is basically as common for beginners to have numpy.py or requests.py or openai.py as it is for them to have random.py, and PyPI is only becoming more and more useful
    • I don't think it is tenable to scan site.getsitepackages (or try to use importlib.metadata.distributions or similar). This can be really slow. Also recursive imports while handling import errors can lead to some really cursed situations that can cause the interpreter to crash

    Are there tweaks that would have made you less confused? For instance:

    • We can restore the error message to lead with "partially initialized module" instead of "module"
    • We can lead with the "if" clause, i.e. "If ... has the same name as a library you intended to import, consider renaming ..." instead of "Consider renaming ... if ...."
  10. hauntsaninja commented on Apr 10, 2026

    @hauntsaninja
    hauntsaninja
    on Apr 10, 2026
    Contributor
    More actions

    Closing, since OP never reacted to my suggestions, and we haven't seen additional cases of confusion

  11. hauntsaninja
    closed this as not plannedon Apr 10, 2026
  12. sausix commented on Apr 10, 2026

    @sausix
    sausix
    on Apr 10, 2026
    Author
    More actions

    I reported a bug. Clearly a regression.
    Then this issue has been automatically closed for reason "Everybody is unaware between the difference of Python and CPython".
    I had to register on another site to open a discussion for reopening this issue.

    Now this issue is on me? I've done enough so far. It's not my job to find a solution for you on a simple issue.

    Yeah just close it if you prefer better statistics than solving issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.