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

Regression fix_imports does not refactor multiple imports correctly #48914

Closed
regebro mannequin opened this issue Dec 14, 2008 · 8 comments
Closed

Regression fix_imports does not refactor multiple imports correctly #48914

regebro mannequin opened this issue Dec 14, 2008 · 8 comments
Labels
topic-2to3 type-bug An unexpected behavior, bug, or error

Comments

@regebro
Copy link
Mannequin

regebro mannequin commented Dec 14, 2008

BPO 4664
Nosy @avassalotti, @benjaminp, @regebro
Files
  • test3.py
  • 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 2008-12-14.21:55:51.485>
    created_at = <Date 2008-12-14.19:07:20.837>
    labels = ['type-bug', 'expert-2to3']
    title = 'Regression fix_imports does not refactor multiple imports correctly'
    updated_at = <Date 2008-12-14.21:55:51.484>
    user = 'https://github.com/regebro'

    bugs.python.org fields:

    activity = <Date 2008-12-14.21:55:51.484>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-12-14.21:55:51.485>
    closer = 'benjamin.peterson'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2008-12-14.19:07:20.837>
    creator = 'lregebro'
    dependencies = []
    files = ['12357']
    hgrepos = []
    issue_num = 4664
    keywords = []
    message_count = 8.0
    messages = ['77815', '77816', '77819', '77824', '77825', '77827', '77831', '77839']
    nosy_count = 3.0
    nosy_names = ['alexandre.vassalotti', 'benjamin.peterson', 'lregebro']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue4664'
    versions = ['Python 3.0']

    @regebro
    Copy link
    Mannequin Author

    regebro mannequin commented Dec 14, 2008

    If you have urlparse before cStringIO in an import line, 2to3 will not
    convert the cStringIO to io. However, reverse the order, and urlparse
    will not get translated.

    So this file:
    import urlparse, cStringIO
    import cStringIO, urlparse

    will with 2to3 return the following diff:

    --- test3.py (original)
    +++ test3.py (refactored)
    @@ -1,3 +1,3 @@
     
    -import urlparse, cStringIO
    -import cStringIO, urlparse
    +import urllib.parse, cStringIO
    +import io, urlparse

    @regebro regebro mannequin added topic-2to3 type-bug An unexpected behavior, bug, or error labels Dec 14, 2008
    @avassalotti
    Copy link
    Member

    Sorry, I still cannot reproduce it. Could you attach your test file?
    Maybe it is some weird encoding bug.

    alex@helios:~$ 2to3 -f imports test.py
    --- test.py (original)
    +++ test.py (refactored)
    @@ -1,2 +1,2 @@
    -import urlparse, cStringIO
    -import cStringIO, urlparse
    +import urllib.parse, io
    +import io, urllib.parse
    RefactoringTool: Files that need to be modified:
    RefactoringTool: test.py

    @avassalotti avassalotti changed the title import urlparse, cStringIO breaks fix_imports does not refactor "import urlparse, cStringIO" correctly Dec 14, 2008
    @benjaminp
    Copy link
    Contributor

    Here's one which doesn't work correctly:

    $ 2to3 -
    RefactoringTool: Skipping implicit fixer: buffer
    RefactoringTool: Skipping implicit fixer: idioms
    RefactoringTool: Skipping implicit fixer: set_literal
    RefactoringTool: Skipping implicit fixer: ws_comma
    import cStringIO, HTMLParser
    --- <stdin> (original)
    +++ <stdin> (refactored)
    @@ -1,1 +1,1 @@
    -import cStringIO, HTMLParser
    +import io, HTMLParser
    RefactoringTool: Files that need to be modified:
    RefactoringTool: <stdin>

    This is because the fix_imports pattern catching one module per import
    statement.

    @regebro
    Copy link
    Mannequin Author

    regebro mannequin commented Dec 14, 2008

    Heres my test file.

    @avassalotti
    Copy link
    Member

    Benjamin, your example fails for a different reason--i.e. the fixer for
    HTMLParser is missing.

    Sorry Lennart, I still cannot reproduce it.

    @regebro
    Copy link
    Mannequin Author

    regebro mannequin commented Dec 14, 2008

    What version are you running? Can you post the output?

    @avassalotti
    Copy link
    Member

    I got it. It is a regression from a previous version of 2to3's
    fix_imports. I was able to reproduce your problem using the sandbox's 2to3.

    And to answer your question, I still running an older RC release of
    Python 3.0. That explains why I couldn't reproduce the problem.

    $ python3.0 -c "import sys; print(sys.version)"
    3.0rc2+ (py3k:67237, Nov 16 2008, 15:10:03) 
    [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)]

    @avassalotti avassalotti changed the title fix_imports does not refactor "import urlparse, cStringIO" correctly Regression fix_imports does not refactor multiple imports correctly Dec 14, 2008
    @benjaminp
    Copy link
    Contributor

    Fixed in r67774.

    @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

    2 participants