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

incorrect renaming in imports #49159

Closed
loewis mannequin opened this issue Jan 10, 2009 · 4 comments
Closed

incorrect renaming in imports #49159

loewis mannequin opened this issue Jan 10, 2009 · 4 comments

Comments

@loewis
Copy link
Mannequin

loewis mannequin commented Jan 10, 2009

BPO 4909
Nosy @loewis, @benjaminp
Files
  • cStringIO_hack.patch
  • 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 2009-01-10.21:12:25.024>
    created_at = <Date 2009-01-10.19:32:32.953>
    labels = ['expert-2to3']
    title = 'incorrect renaming in imports'
    updated_at = <Date 2009-01-10.21:12:25.016>
    user = 'https://github.com/loewis'

    bugs.python.org fields:

    activity = <Date 2009-01-10.21:12:25.016>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-01-10.21:12:25.024>
    closer = 'benjamin.peterson'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2009-01-10.19:32:32.953>
    creator = 'loewis'
    dependencies = []
    files = ['12681']
    hgrepos = []
    issue_num = 4909
    keywords = ['patch']
    message_count = 4.0
    messages = ['79568', '79576', '79577', '79578']
    nosy_count = 2.0
    nosy_names = ['loewis', 'benjamin.peterson']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue4909'
    versions = []

    @loewis
    Copy link
    Mannequin Author

    loewis mannequin commented Jan 10, 2009

    The fragment

    try:
    import cStringIO as StringIO
    except ImportError:
    import StringIO
    s=StringIO.StringIO()

    gets rewritten to

    try:
    import io as StringIO
    except ImportError:
    import io
    s=io.StringIO()

    Unfortunately, that code fails to work: the first import succeeds,
    actually binding StringIO; the name io is unbound and gives NameError.

    Apparently, the fixer choses to replace all occurrences of StringIO with
    io; it should extend this replacement to "as" clauses.

    My work-around is to import as _StringIO in both cases, and then refer
    to the module as _StringIO.

    @loewis loewis mannequin added the topic-2to3 label Jan 10, 2009
    @benjaminp
    Copy link
    Contributor

    Tricky. I only solution I can think of is replacing cStringIO with
    _stringio or just refusing to replace StringIO usage once cStringIO has
    been seen. The latter seems like the best solutions.

    @loewis
    Copy link
    Mannequin Author

    loewis mannequin commented Jan 10, 2009

    If there is no straight-forward solution, we should close it as "won't
    fix", and encourage users to work around.

    @benjaminp
    Copy link
    Contributor

    Ok. I will close this for now. This is a very common construct; if we
    get more bug reports, we can reconsider. (I'm attaching the patch I used
    to "fix" this for future reference.)

    @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
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant