Issue 16773: int() half-accepts UserString (original) (raw)

Issue16773

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 "", line 1, in 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 .
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 -> closedsuperseder: UserString can not be used as string in calls to C routinesmessages: + resolution: duplicatestage: needs patch -> resolved
2012-12-30 19:36:27 serhiy.storchaka set messages: +
2012-12-30 17:51:48 ezio.melotti set messages: +
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🔞07 ezio.melotti set nosy: + ezio.melotti
2012-12-24 20:15:15 serhiy.storchaka create