[Python-3000] More PEP 3101 changes incoming

Adam Olsen rhamph at gmail.com
Sat Aug 4 07:13:05 CEST 2007


On 8/3/07, Adam Olsen <rhamph at gmail.com> wrote:
> class MyFloat:
> def __format__(self, type, ...):
> if type == 'D':
> return custom format
> else:
> return float(self).__format__(type, ...)

Oops, explicitly falling back to float is unnecessary here. It should
instead be:
class MyFloat:
 def __float__(self):
 return self as float
 def __format__(self, type, ...):
 if type == 'D':
 return custom format
 else:
 return NotImplemented # Falls back to self.__float__().__format__()
-- 
Adam Olsen, aka Rhamphoryncus


More information about the Python-3000 mailing list

AltStyle によって変換されたページ (->オリジナル) /