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

2to3 import fixer writes dotted_as_names into import_as_names #66615

Closed
simonmweber mannequin opened this issue Sep 16, 2014 · 1 comment
Closed

2to3 import fixer writes dotted_as_names into import_as_names #66615

simonmweber mannequin opened this issue Sep 16, 2014 · 1 comment
Labels
topic-2to3 type-bug An unexpected behavior, bug, or error

Comments

@simonmweber
Copy link
Mannequin

simonmweber mannequin commented Sep 16, 2014

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']

    @simonmweber
    Copy link
    Mannequin Author

    simonmweber mannequin commented Sep 16, 2014

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

    @simonmweber simonmweber mannequin added topic-2to3 type-bug An unexpected behavior, bug, or error labels Sep 16, 2014
    @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
    topic-2to3 type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant