Forgetting "()" when calling methods

Alex Martelli aleax at
Sun Apr 27 09:38:47 CEST 2003

Andrew Bennetts wrote:
> For that matter, removing __nonzero__ from functions still doesn't help
> this case:
>     sys.exit
> So it's of pretty minimal benefit.

Not really.  Write the following file:

import sys

and now run:

[alex at lancelot booksa]$ pychecker
Processing erro...

Warnings... Statement appears to have no effect
[alex at lancelot booksa]$

See?  PyChecker CAN and DOES warn about "this case"!  But OF COURSE
it can't help with the following

import sys
if sys.exit:
    print 'ha!'

[alex at lancelot booksa]$ pychecker
Processing erro1...


[alex at lancelot booksa]$

So, _if_ we could avoid functions and methods being usable as bools,
we'd help get (ASAP, at runtime) some errors that PyCheccker *CANNOT*
get through its static analysis.

This may not be doable if we need to support the given getattr idiom
if f: ...
rather than requiring an "if f is None:".  And it may not be worth
doing, since the people who I think would be helped by this appear to
insist PyChecker should do it (apparently getting a prompt runtime
error isn't sufficient for them -- it must be PyChecker) and PyCheker
just can't.  But, for those of us that see PyChecker and runtime errors
in SINERGY (i.e., things are reasonably fine as long as AT LEAST ONE
of these catches an error early), the benefit wouldn't be minimal, IMHO.


More information about the Python-list mailing list