Skip to content

2to3 creates illegal code on import a.b inside a package #57073

Closed

Description

@simohe
mannequin
BPO 12864
Nosy @benjaminp, @merwok, @meadori
Superseder
  • bpo-45544: Close 2to3 issues and list them here
  • 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-10-20.22:37:18.398>
    created_at = <Date 2011-08-30.21:59:21.221>
    labels = ['expert-2to3']
    title = '2to3 creates illegal code on import a.b inside a package'
    updated_at = <Date 2021-10-20.22:40:51.147>
    user = 'https://bugs.python.org/simohe'

    bugs.python.org fields:

    activity = <Date 2021-10-20.22:40:51.147>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-20.22:37:18.398>
    closer = 'iritkatriel'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2011-08-30.21:59:21.221>
    creator = 'simohe'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 12864
    keywords = []
    message_count = 3.0
    messages = ['143237', '156737', '156738']
    nosy_count = 4.0
    nosy_names = ['benjamin.peterson', 'eric.araujo', 'meador.inge', 'simohe']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = '45544'
    type = None
    url = 'https://bugs.python.org/issue12864'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    Activity

    1. simohe commented on Aug 30, 2011

      simohemannequin
      MannequinAuthor

      When the current module is in a package and imports submodules, the following lines are converted to illegal code.

      -import sub.subsub
      +from . import sub.subsub

      -import sub, sub.subsub, sub2
      +from . import sub, sub.subsub, sub2

      A valid alternative:

      -import sub.subsub
      +from .sub import subsub as _dummy

      -import sub, sub.subsub, sub2
      +from . import sub, sub2\nfrom .sub import subsub as _dummy

    2. merwok commented on Mar 25, 2012

      @merwok
      Member

      -import sub.subsub
      +from .sub import subsub as _dummy

      That’s partly incorrect, as you need to bind the name sub to match the original code.

    3. merwok commented on Mar 25, 2012

      @merwok
      Member

      BTW I think if this is too difficult to implement 2to3 could just be documented as requiring you not to use implicit relative imports.

    4. 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

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions