[New-bugs-announce] [issue5759] Do not call __float__ to classec derived from str
Alexandr Zamaraev
report at bugs.python.org
Wed Apr 15 05:41:02 CEST 2009
New submission from Alexandr Zamaraev <shura_zam at users.sourceforge.net>:
Test case:
[code]
class S:
def __init__(self, v):
self.data = v
def __int__(self):
print("S.INT called")
return int(str(self.data))
def __float__(self):
print("S.FLOAT called")
return float(str(self.data))
class T(str):
def __int__(self):
print("T.INT called")
return int(str(self))
def __float__(self):
print("T.FLOAT called")
return float(str(self))
class U(unicode):
def __int__(self):
print("U.INT called")
return int(unicode(self))
def __float__(self):
print("U.FLOAT called")
return float(unicode(self))
i = S("123")
print(type(int(i)))
print(type(float(i)))
i = T("123")
print(type(int(i)))
print(type(float(i))) # <<< CALLS __float__ NOTHING
i = U("123")
print(type(int(i)))
print(type(float(i)))
[/code]
Output:
[code]
S.INT called
<type 'int'>
S.FLOAT called
<type 'float'>
T.INT called
<type 'int'>
<type 'float'>
U.INT called
<type 'int'>
U.FLOAT called
<type 'float'>
[/code]
----------
components: None
messages: 85979
nosy: shura_zam
severity: normal
status: open
title: Do not call __float__ to classec derived from str
versions: Python 2.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5759>
_______________________________________
More information about the New-bugs-announce
mailing list