New submission from Alexandr Zamaraev <shura_...@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 <rep...@bugs.python.org> <http://bugs.python.org/issue5759> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com