Mixing Decimal and float

Nathan Rice nathan.alexander.rice at gmail.com
Wed Jun 2 17:17:11 EDT 2010


My apologies if someone already mentioned this and I missed it but...

class.__instancecheck__(self, instance) - Return true if instance
should be considered a (direct or indirect) instance of class. If
defined, called to implement isinstance(instance, class).

class.__subclasscheck__(self, subclass) - Return true if subclass
should be considered a (direct or indirect) subclass of class. If
defined, called to implement issubclass(subclass, class).

Nathan

On Wed, Jun 2, 2010 at 4:24 AM, B.V. <bv.tryton at gmail.com> wrote:
> Hi,
>
> In order to solve some issues due to operations between Decimal and
> float, we wanted to implement a class that inherits from both float
> and Decimal.
>
> Typically, we wrote:
> class Float(Decimal, float):
> ...
>
> This can not be achieved because of a TypeError exception (with
> message "multiple bases have instance lay-out conflict").
>
> With a class that inherits from Decimal, with overridden __add__,
> __mul__, .... , we succeed to solve operations issues.
>
> But we also need to do:
> isinstance(Float('1'), float) == True
> isinstance(Float('1'), Decimal) == True
> which is, AFAIK, only possible with Float(Decimal, float).
>
> Is there a workaround ?
>
> We are developping with python version 2.5 and 2.6.
>
> Thanks for your help.
>
> B.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list