Hacking with __new__

Duncan Booth duncan.booth at invalid.invalid
Tue Jul 24 15:00:59 EDT 2007


Bruno Desthuilliers <bruno.42.desthuilliers at wtf.websiteburo.oops.com> 
wrote:

> Duncan Booth a écrit :
> (snip)
>> I think what you want for Bar is something more along the lines:
> 
> (snip)
> 
>> class Bar(Foo):
>>     def __new__(cls, a, b, c, *args):
>>         print 'Bar.__new__', len(args)
>>         target = cls
> You don't use 'target' anywhere...
> 
>>         if not args:
>>             cls = Zoo
>>         obj = super(Bar, cls).__new__(cls, a, b, c, *args)
>>         if args:
>>             return obj
>> 
>>         obj.__init__(a, b, c, 7)
> 
> IIRC, __new__ is supposed to return the newly created object - which you 
> are not doing here.
> 
Yup. I committed that cardinal sin of checking the code and then tidying it 
up by hand but not checking the tidied version. :(





More information about the Python-list mailing list