classification
Title: 2to3 fails to convert types.StringTypes appropriately
Type: enhancement Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: benjamin.peterson Nosy List: BreamoreBoy, benjamin.peterson, meador.inge, mhammond, python-dev, r.david.murray, rbcollins
Priority: normal Keywords: patch

Created on 2012-02-04 05:31 by mhammond, last changed 2015-07-22 19:43 by rbcollins. This issue is now closed.

Files
File name Uploaded Description Edit
fix_stringtypes_fixer.patch mhammond, 2012-02-04 05:31 fix and test review
Messages (9)
msg152592 - (view) Author: Mark Hammond (mhammond) * (Python committer) Date: 2012-02-04 05:31
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.
msg222130 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-02 21:29
A short patch LGTM.  Can we have a commit review please.
msg247140 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-07-22 18:19
New changeset b97b6cc381d7 by Robert Collins in branch 'default':
Issue #13938: 2to3 converts StringTypes to a tuple. Patch from Mark Hammond.
https://hg.python.org/cpython/rev/b97b6cc381d7
msg247141 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2015-07-22 18:19
I've applied this to 3.6.
msg247142 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-07-22 18:26
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.
msg247144 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2015-07-22 18:42
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.
msg247146 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-07-22 18:55
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 :)
msg247147 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2015-07-22 19:05
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 ? :)
msg247149 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-07-22 19:42
New changeset ce34c78ebf65 by Robert Collins in branch '2.7':
Issue #13938: 2to3 converts StringTypes to a tuple. Patch from Mark Hammond.
https://hg.python.org/cpython/rev/ce34c78ebf65
History
Date User Action Args
2015-07-22 19:43:16rbcollinssetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2015-07-22 19:42:01python-devsetmessages: + msg247149
2015-07-22 19:05:03rbcollinssetmessages: + msg247147
2015-07-22 18:55:34r.david.murraysetmessages: + msg247146
2015-07-22 18:42:21rbcollinssetmessages: + msg247144
2015-07-22 18:26:25r.david.murraysetnosy: + r.david.murray
messages: + msg247142
2015-07-22 18:19:46rbcollinssetnosy: + rbcollins
messages: + msg247141
2015-07-22 18:19:27python-devsetnosy: + python-dev
messages: + msg247140
2014-08-22 09:32:11Claudiu.Popasettype: enhancement
stage: commit review
2014-07-02 21:29:15BreamoreBoysetnosy: + BreamoreBoy

messages: + msg222130
versions: + Python 3.4, Python 3.5, - Python 3.2, Python 3.3
2012-02-16 05:10:02meador.ingesetnosy: + meador.inge
2012-02-06 15:50:21eric.araujosetassignee: benjamin.peterson

nosy: + benjamin.peterson
versions: + Python 2.7, - Python 3.4
2012-02-04 05:31:32mhammondcreate