Skip to content

2to3 import fixer writes dotted_as_names into import_as_names #66615

Closed

Description

@simonmweber
BPO 22425
Nosy @benjaminp
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:45:13.073>
    created_at = <Date 2014-09-16.21:00:27.078>
    labels = ['type-bug', 'expert-2to3']
    title = '2to3 import fixer writes dotted_as_names into import_as_names'
    updated_at = <Date 2021-10-20.22:45:13.072>
    user = 'https://bugs.python.org/simonmweber'

    bugs.python.org fields:

    activity = <Date 2021-10-20.22:45:13.072>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-20.22:45:13.073>
    closer = 'iritkatriel'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2014-09-16.21:00:27.078>
    creator = 'simonmweber'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 22425
    keywords = []
    message_count = 1.0
    messages = ['226965']
    nosy_count = 3.0
    nosy_names = ['benjamin.peterson', 'Arfrever', 'simonmweber']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = '45544'
    type = 'behavior'
    url = 'https://bugs.python.org/issue22425'
    versions = ['Python 2.7', 'Python 3.4']

    Activity

    1. simonmweber commented on Sep 16, 2014

      simonmwebermannequin
      MannequinAuthor

      When dealing with implicit relative imports of the form "import <dotted_as_names> as...", the 2to3 import fixer will rewrite them as "from . import <dotted_as_names> as...".

      This is invalid syntax. Here's an example:

      $ tree package/
      package/
      ├── __init__.py
      ├── rootmod.py
      └── subpackage
          ├── __init__.py
          └── mod.py

      1 directory, 4 files

      $ cat package/rootmod.py  # this is the only nonempty file
      import subpackage.mod as my_name
      
      $ python package/rootmod.py
      $ 2to3 -w -f import package/
      RefactoringTool: Refactored package/rootmod.py
      --- package/rootmod.py	(original)
      +++ package/rootmod.py	(refactored)
      @@ -1 +1 @@
      -import subpackage.mod as my_name
      +from . import subpackage.mod as my_name
      RefactoringTool: Files that were modified:
      RefactoringTool: package/rootmod.py
      $ python package/rootmod.py
        File "package/rootmod.py", line 1
          from . import subpackage.mod as my_name
                                  ^
      SyntaxError: invalid syntax

      Probably the easiest way to rewrite this is "from .subpackage import mod as my_name".

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

      topic-2to3type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions