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.
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:46 | admin | set | github: 49675 |
| 2009年03月18日 21:13:30 | benjamin.peterson | set | status: open -> closed messages: + msg83777 |
| 2009年03月08日 14:29:49 | hagen | set | status: closed -> open files: + 2to3_StringTypes_2.patch messages: + msg83311 |
| 2009年03月07日 19:39:47 | ajaksu2 | set | nosy:
+ ajaksu2 messages: + msg83289 |
| 2009年03月07日 09:42:44 | hagen | set | messages: + msg83276 |
| 2009年03月06日 19:10:48 | loewis | set | messages: + msg83252 |
| 2009年03月06日 06:59:49 | hagen | set | messages: + msg83240 |
| 2009年03月05日 21:50:25 | benjamin.peterson | set | status: open -> closed resolution: rejected |
| 2009年03月05日 21:47:28 | loewis | set | nosy:
+ loewis messages: + msg83221 |
| 2009年03月05日 20:16:28 | benjamin.peterson | set | nosy:
+ benjamin.peterson messages: + msg83215 |
| 2009年03月05日 14:48:48 | hagen | create | |