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 fails to convert types.StringTypes appropriately #58146

Closed
mhammond opened this issue Feb 4, 2012 · 9 comments
Closed

2to3 fails to convert types.StringTypes appropriately #58146

mhammond opened this issue Feb 4, 2012 · 9 comments
Assignees
Labels
topic-2to3 type-feature A feature request or enhancement

Comments

@mhammond
Copy link
Contributor

mhammond commented Feb 4, 2012

BPO 13938
Nosy @mhammond, @rbtcollins, @benjaminp, @bitdancer, @meadori
Files
  • fix_stringtypes_fixer.patch: fix and test
  • 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 = 'https://github.com/benjaminp'
    closed_at = <Date 2015-07-22.19:43:16.795>
    created_at = <Date 2012-02-04.05:31:32.920>
    labels = ['type-feature', 'expert-2to3']
    title = '2to3 fails to convert types.StringTypes appropriately'
    updated_at = <Date 2015-07-22.19:43:16.794>
    user = 'https://github.com/mhammond'

    bugs.python.org fields:

    activity = <Date 2015-07-22.19:43:16.794>
    actor = 'rbcollins'
    assignee = 'benjamin.peterson'
    closed = True
    closed_date = <Date 2015-07-22.19:43:16.795>
    closer = 'rbcollins'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2012-02-04.05:31:32.920>
    creator = 'mhammond'
    dependencies = []
    files = ['24415']
    hgrepos = []
    issue_num = 13938
    keywords = ['patch']
    message_count = 9.0
    messages = ['152592', '222130', '247140', '247141', '247142', '247144', '247146', '247147', '247149']
    nosy_count = 7.0
    nosy_names = ['mhammond', 'rbcollins', 'benjamin.peterson', 'r.david.murray', 'meador.inge', 'BreamoreBoy', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue13938'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @mhammond
    Copy link
    Contributor Author

    mhammond commented Feb 4, 2012

    test_types.py converts "types.StringTypes" to "str" - but types.StringTypes is a tuple, so expressions like "type(x) in type.StringTypes" fails after conversion with "TypeError: argument of type 'type' is not iterable"

    Attaching a fix and test.

    Note that the fixer still seems "strange" after this fix - types.StringType gets converted to "bytes" but types.StringTypes uses str. This means the expression "type.StringType in type.StringTypes" evaluates to True in 2.x but False once converted - however, that should probably be tackled in a different bug - the fact the expression now causes a TypeError once converted is more blatantly wrong and the focus of this bug.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 2, 2014

    A short patch LGTM. Can we have a commit review please.

    @PCManticore PCManticore mannequin added the type-feature A feature request or enhancement label Aug 22, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 22, 2015

    New changeset b97b6cc381d7 by Robert Collins in branch 'default':
    Issue bpo-13938: 2to3 converts StringTypes to a tuple. Patch from Mark Hammond.
    https://hg.python.org/cpython/rev/b97b6cc381d7

    @rbtcollins
    Copy link
    Member

    I've applied this to 3.6.

    @bitdancer
    Copy link
    Member

    Looking at the audit log its not clear to me which versions Benjamin wanted this applied to, though it looks like 2.7 at least.

    @rbtcollins
    Copy link
    Member

    Not clear to me either: I figured that after three years the relevance to 2.7 was pretty low, but I can transplant it if you think thats relevant.

    @bitdancer
    Copy link
    Member

    Well, it's a patch to 2to3, which I'm assuming is sometimes (often?) run using 2.7 to convert code to run under python3.

    I personally don't use transplant in cases like this, I just apply the patch independently to the 2.7 branch. That may just be because I've never used transplant, but we are treating the two branches as independent and I don't want to screw that up :)

    @rbtcollins
    Copy link
    Member

    So, I don't think I've ever done 2.x stuff with hg here, I'll leave this open till I've looked up the docs and applied it safely.

    ... unless you'd like to do the 2.7 application ? :)

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 22, 2015

    New changeset ce34c78ebf65 by Robert Collins in branch '2.7':
    Issue bpo-13938: 2to3 converts StringTypes to a tuple. Patch from Mark Hammond.
    https://hg.python.org/cpython/rev/ce34c78ebf65

    @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-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants