Forgetting "()" when calling methods

Alex Martelli aleax at
Sun Apr 27 09:45:07 CEST 2003

Terry Reedy wrote:

> "Erik Max Francis" <max at> wrote in message
> news:3EAB6A14.707AD826 at
>> Jeremy Fincher wrote:
>> > Perhaps the answer is to remove the __nonzero__ method on
>> > functions/methods.  Logically, what purpose does it serve?
>> # f holds a callable object or None
>> if f:
>>     f(...)
> or
> print f and f() or 'cannot do that' # assumes boo(f()) always True
> I consider it a feature that all objects have truth value (except for
> perversely written user classes), so that conditional expressions and
> statements always work without exception.

It's a feature, just like it WAS a feature that you USED TO be able
to always test "if a>b:" without exception.  But features can and do
get removed when it's deemed too likely that they "let errors pass
silently" -- the ability to compare a>b unrestrictedly was removed
in the move 2.0 -> 2.1 (when either comparand is a complex and the
other any kind of number) and it may get restricted even further.  By
the same token, the ability to "use the truth value" of a function or
method object COULD be removed for similar reasons.

It's sad that this enhancement cannot be used, to support such tests
as "if f:" rather than "if f is not None:".  But -- I would HOPE
somebody tried to make to the BDFL that "the use case" for keeping
functions and methods 'true' would be that horrid single-line print,
so unreadable, fragile, and unPythonic... if you managed to convince
him that THIS is the usage that such truth values empower, then I
think we'd see the truth value go away by 2.3 beta 2!-)


More information about the Python-list mailing list