Forgetting "()" when calling methods

Erik Max Francis max at alcyone.com
Fri Apr 25 18:27:25 EDT 2003


Frantisek Fuka wrote:

> You can say to me "Don't forget to always include the parenteses" but
> I'm still curious if this cannot be somehow configured, so that I get
> error when I try to just access the method pointer (".isGreen")
> instead
> of calling the method (".isGreen()"). I understand that there has to
> be
> the possibility of accessing the method pointers but I usually don't
> need it and for a beginner like me this makes the applications very
> hard
> to debug.

There might be a PyChecker option, but I wouldn't count on it, since due
to Python's dynamic nature there's no real way for the interpreter (or
PyChecker) to know that you meant to call the attribute rather than test
its value as a Boolean.  (After all, at the time that code gets run,
object.isGreen could be anything at all.)

One thing that PyChecker, at least, is more likely to catch is "code has
no effect" statements like

	sys.exit

Without the parentheses, this clearly can't do anything useful, just
like

	2 + 2

I can't recall offhand whether or not PyChecker detects this type of
logical error; I would suspect it probably does or will soon.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ To perceive is to suffer.
\__/ Aristotle
    Python chess module / http://www.alcyone.com/pyos/chess/
 A chess game adjudicator in Python.




More information about the Python-list mailing list