This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 2to3 wrong for types.StringTypes
Type: behavior Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, benjamin.peterson, hagen, loewis
Priority: normal Keywords: patch

Created on 2009-03-05 14:48 by hagen, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
2to3_StringTypes.patch hagen, 2009-03-05 14:48
2to3_StringTypes_2.patch hagen, 2009-03-08 14:29
Messages (9)
msg83198 - (view) Author: Hagen Fürstenau (hagen) Date: 2009-03-05 14:48
In Python 2.6 we have

>>> types.StringTypes
(<type 'str'>, <type 'unicode'>)

but 2to3 translates "types.StringTypes" into "str", which is obviously
wrong. The attached patch changes it into "(str, bytes)".
msg83215 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-03-05 20:16
It's hard to guess the intention of types.StringTypes since it may mean
"text" strings or "text and byte" strings. I'm tempted to just remove
the transformation at all and issue a warning.
msg83221 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-03-05 21:47
I agree with Benjamin. Translation into (str, bytes) is incorrect. I
don't agree that it is obvious that the translation into str is incorrect.

Recommend closing as reject.
msg83240 - (view) Author: Hagen Fürstenau (hagen) Date: 2009-03-06 06:59
Why I considered the existing translation incorrect was because it
translates something which was a tuple of types in Python 2.x into a
type of Python 3.x. I fail to see how this can be useful. (A check like
"x in types.StringTypes" gets translated into "x in str", which will
always fail.)

I agree that translating into "(str, bytes)" won't always be correct,
but it seems to have a much better chance of being correct than the
existing translation into "str". Otherwise it should at least be "(str,)".
msg83252 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-03-06 19:10
> Why I considered the existing translation incorrect was because it
> translates something which was a tuple of types in Python 2.x into a
> type of Python 3.x. I fail to see how this can be useful. 

It would translate "isinstance(x, types.StringTypes)" correctly. I agree
that translating to a tuple would be correct in more cases.
msg83276 - (view) Author: Hagen Fürstenau (hagen) Date: 2009-03-07 09:42
I can see the merit of not including "bytes" in StringTypes, but then
the translation of StringType should be changed accordingly. How about
changing the present

StringType -> bytes
StringTypes -> str

into

StringType -> str
StringTypes -> (str,)
msg83289 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-03-07 19:39
I think Hagen's initial analysis makes more sense: the translation is
currently guessing that the user meant the more restrict (text) alternative.

IMHO it doesn't make much sense to have this:
>>> strings = (types.StringType, types.UnicodeType)
>>> strings == types.StringTypes
True

Translated to this:
strings = (bytes, str)
strings == str
msg83311 - (view) Author: Hagen Fürstenau (hagen) Date: 2009-03-08 14:29
The automatic conversion can't be perfect in all cases, but I think my
second suggestion is more in line with the other transformations done by
2to3 (string literals, "str", "basestring" etc.).

I propose applying the second patch, but don't care enough to argue for
it much more if it's rejected.
msg83777 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-03-18 21:13
I'm rejecting this patch again not because I think it's any worse than
the status quo (I think they're about equally incorrect/correct), but
because this is now released behavior and changing it may result in
backwards incompatibility. Also, people can easily remove this ambiguity
in a 2.x compatible fashion by explicitly listing the types (str,) or
(str, unicode) instead of using the types module.
History
Date User Action Args
2022-04-11 14:56:46adminsetgithub: 49675
2009-03-18 21:13:30benjamin.petersonsetstatus: open -> closed

messages: + msg83777
2009-03-08 14:29:49hagensetstatus: closed -> open
files: + 2to3_StringTypes_2.patch

messages: + msg83311
2009-03-07 19:39:47ajaksu2setnosy: + ajaksu2
messages: + msg83289
2009-03-07 09:42:44hagensetmessages: + msg83276
2009-03-06 19:10:48loewissetmessages: + msg83252
2009-03-06 06:59:49hagensetmessages: + msg83240
2009-03-05 21:50:25benjamin.petersonsetstatus: open -> closed
resolution: rejected
2009-03-05 21:47:28loewissetnosy: + loewis
messages: + msg83221
2009-03-05 20:16:28benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg83215
2009-03-05 14:48:48hagencreate