I am redefining int() and float() for my number-like class (simplified floatoverload class below), but I get a TypeError
when trying to use float(). I am returning a floating point number from __float__ ( ).
int( ) works fine.
Any pointers on what might would be much appreciated. I am using:
MicroPython v1.10-278-g673e154df-dirty on 2019-04-16; win32 version
EDIT: This code works with CPython (tried using 3.6.8)
Code: Select all
class floatoverload (object):
def __init__ (self):
pass
def __float__ (self):
return 99.9
def __int__ (self):
return 999
Code: Select all
>>> from floatoverload import floatoverload
>>> int(floatoverload())
999
>>> float(floatoverload())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert floatoverload to float
>>>