Skip to content

Improve AttributeError on circular imports of submodules #88880

Closed

Description

@FFY00
BPO 44717
Nosy @ambv, @pablogsal, @FFY00
PRs
  • bpo-44717: improve AttributeError on circular imports of submodules #27299
  • bpo-44717: Revert "improve AttributeError on circular imports of submodules" #27331
  • bpo-44717: improve AttributeError on circular imports of submodules #27338
  • bpo-44717: refactor _PyModuleSpec helpers #27344
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-07-24.22:45:30.358>
    created_at = <Date 2021-07-23.00:51:19.896>
    labels = ['interpreter-core', 'type-feature']
    title = 'Improve AttributeError on circular imports of submodules'
    updated_at = <Date 2021-07-25.01:27:23.066>
    user = 'https://github.com/FFY00'

    bugs.python.org fields:

    activity = <Date 2021-07-25.01:27:23.066>
    actor = 'FFY00'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-07-24.22:45:30.358>
    closer = 'pablogsal'
    components = ['Interpreter Core']
    creation = <Date 2021-07-23.00:51:19.896>
    creator = 'FFY00'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44717
    keywords = ['patch']
    message_count = 6.0
    messages = ['398021', '398134', '398135', '398146', '398154', '398176']
    nosy_count = 3.0
    nosy_names = ['lukasz.langa', 'pablogsal', 'FFY00']
    pr_nums = ['27299', '27331', '27338', '27344']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue44717'
    versions = []

    Activity

    1. FFY00 commented on Jul 23, 2021

      @FFY00
      MemberAuthor

      Consider the following

      $ tree a
      a
      ├── b
      │   ├── c.py
      │   └── __init__.py
      └── __init__.py

      1 directory, 3 files
      $ cat a/b/init.py
      import a.b.c
      $ cat a/b/c.py
      import a.b

      a.b
      $ python
      Python 3.9.6 (default, Jun 30 2021, 10:22:16)
      [GCC 11.1.0] on linux
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import a.b
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/home/anubis/test/a/b/__init__.py", line 1, in <module>
          import a.b.c
        File "/home/anubis/test/a/b/c.py", line 3, in <module>
          a.b
      AttributeError: module 'a' has no attribute 'b'

      This happens because even though the module a is initialized, the b attribute is not set due to the circular import. When a module is partially initialized, we get a more helpful error description hinting that we cannot access the attribute because the module is partially initialized, we could have something similar here.

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-featureA feature request or enhancement
      on Jul 23, 2021
    3. ambv commented on Jul 24, 2021

      @ambv
      Contributor

      New changeset 8072a11 by Filipe Laíns in branch 'main':
      bpo-44717: improve AttributeError on circular imports of submodules (GH-27299)
      8072a11

    4. ambv commented on Jul 24, 2021

      @ambv
      Contributor

      Thanks a lot for your report and patch, Filipe! ✨ 🍰 ✨

    5. pablogsal commented on Jul 24, 2021

      @pablogsal
      Member

      There is a buildbot failure after merging this PR:

      https://buildbot.python.org/all/#/builders/464/builds/574

      If is not fixed in 24 we will need to revert per our buildbot policy

    6. pablogsal commented on Jul 24, 2021

      @pablogsal
      Member

      New changeset 3eae8f2 by Pablo Galindo Salgado in branch 'main':
      Revert "bpo-44717: improve AttributeError on circular imports of submodules (GH-27299)" (GH-27331)
      3eae8f2

    7. pablogsal commented on Jul 24, 2021

      @pablogsal
      Member

      New changeset 0a8ae8a by Filipe Laíns in branch 'main':
      bpo-44717: improve AttributeError on circular imports of submodules (GH-27338)
      0a8ae8a

    8. transferred this issue fromon Apr 10, 2022
    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)type-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions