__call__ considered harmful or indispensable?

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Fri Aug 3 04:01:06 EDT 2007


Skip Montanaro a écrit :
>>> In this case there was a bug.  Depending on inputs, sometimes obj
>>> initialized to a class, sometimes an instance of that class.  (I fixed
>>> that too while I was at it.)  The problem was that the use of __call__
>>> obscured the underlying bug by making the instance as well as the class
>>> callable.
> 
>> I don't quite get the point here. A concrete example would be welcome.
> 
> The bug went something like this:
> 
>     obj = some.default_class
>     ...
>     if some_other_rare_condition_met:
>         ... several lines ...
>         obj = some.other_class()
>     ...
> 
> Later,
> 
>     x = obj()
>     x(...)

Ok, I see. A nasty one, indeed.




More information about the Python-list mailing list