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 2012年12月24日 20:15 by serhiy.storchaka, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg178096 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2012年12月24日 20:15 | |
In Python 3 int() accepts UserString argument without explicit base and reject it with explicit base.
>>> from collections import UserString
>>> int(UserString('100'))
100
>>> int(UserString('100'), 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: int() can't convert non-string with explicit base
In 2.7 the same behavior also for MutableString and bytearray.
|
|||
| msg178593 - (view) | Author: Ezio Melotti (ezio.melotti) * (Python committer) | Date: 2012年12月30日 17:51 | |
Not sure this is worth fixing, unless the fix is trivial. |
|||
| msg178605 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2012年12月30日 19:36 | |
This is definitely non-trivial. 1-argument int() works with UserString because __int__() method is defined for UserString (as __float__(), as __complex__()). I.e. UserString looks as number-like for it. Unfortunately there is no way to make a class be string-like without inheriting it from str class. |
|||
| msg225259 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年08月13日 06:47 | |
Looks as there is no easy fix of this issue. This issue is particular case of issue232493. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:39 | admin | set | github: 60977 |
| 2014年08月13日 06:47:14 | serhiy.storchaka | set | status: open -> closed superseder: UserString can not be used as string in calls to C routines messages: + msg225259 resolution: duplicate stage: needs patch -> resolved |
| 2012年12月30日 19:36:27 | serhiy.storchaka | set | messages: + msg178605 |
| 2012年12月30日 17:51:48 | ezio.melotti | set | messages: + msg178593 |
| 2012年12月25日 20:48:05 | mark.dickinson | set | nosy:
+ mark.dickinson |
| 2012年12月25日 08:36:50 | esc24 | set | nosy:
+ esc24 |
| 2012年12月24日 20:22:45 | chris.jerdonek | set | nosy:
+ chris.jerdonek |
| 2012年12月24日 20:18:07 | ezio.melotti | set | nosy:
+ ezio.melotti |
| 2012年12月24日 20:15:15 | serhiy.storchaka | create | |