Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve AttributeError on circular imports of submodules #88880

Closed
FFY00 opened this issue Jul 23, 2021 · 6 comments
Closed

Improve AttributeError on circular imports of submodules #88880

FFY00 opened this issue Jul 23, 2021 · 6 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@FFY00
Copy link
Member

FFY00 commented Jul 23, 2021

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 = []

    @FFY00
    Copy link
    Member Author

    FFY00 commented Jul 23, 2021

    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.

    @FFY00 FFY00 added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Jul 23, 2021
    @ambv
    Copy link
    Contributor

    ambv commented Jul 24, 2021

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

    @ambv
    Copy link
    Contributor

    ambv commented Jul 24, 2021

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

    @ambv ambv closed this as completed Jul 24, 2021
    @ambv ambv closed this as completed Jul 24, 2021
    @pablogsal
    Copy link
    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

    @pablogsal pablogsal reopened this Jul 24, 2021
    @pablogsal pablogsal reopened this Jul 24, 2021
    @pablogsal
    Copy link
    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

    @pablogsal
    Copy link
    Member

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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants