A possible change to decimal.Decimal?

Ethan Furman ethan at stoneleaf.us
Sun Mar 4 16:38:58 CET 2012


A. Lloyd Flanagan wrote:
> On Friday, March 2, 2012 6:49:39 PM UTC-5, Ethan Furman wrote:
>> Jeff Beardsley wrote:
>>> HISTORY:  
> ...
>> What you should be doing is:
>>
>>    import decimal
>>    from decimal import Decimal
>>
>>    reload(decimal)
>>    Decimal = decimal.Decimal   # (rebind 'Decimal' to the reloaded code)
>>
>> ~Ethan~
> 
> Agree that's how the import should be done. On the other hand, removing gratuitous use of isinstance() is generally a Good Thing.

Gratuitous use?  How is it gratuitous for an class to check that one of 
its arguments is its own type?

class Frizzy(object):
     def __add__(self, other):
         if not isinstance(other, Frizzy):
             return NotImplemented
         do_stuff_with(self, other)

This is exactly what isinstance() is for, and this is how it is being 
used in Decimal.__init__().

~Ethan~



More information about the Python-list mailing list