Overloading operators for currying, a PEP309 suggestion

Bernhard Herzog bh at intevation.de
Wed Mar 12 07:13:18 EST 2003


Stephen Horne <intentionally at blank.co.uk> writes:

> Why would a function object be treated as a boolean?

Some functions accept optional callbacks. Naive implementations of such
functions might simply test whether the callback argument is true and
not whether it is None. I fell into a similar trap once when I added the
sequence interface to a class that didn't previously have it.

Of course, as Jp Calderone pointed out, this particular problem can be
worked around by also implementing __nonzero__ to return true even if
the length is zero. That would be a bit inconsistent with the other
builtin objects that support len, though.

   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
MapIt!                                           http://www.mapit.de/




More information about the Python-list mailing list