I found the following mistake in my code this week:
import datetime
d = datetime.date(2010,9,24)
if d.isoweekday == 5:
pass
Yes, it should be d.isoweekday() instead.
I know, if I had had a test-case for this I would have been saved.
Comparing a function with 5 is not very useful. Oh, I’m not blaming Python for this.
My question: Are there tools that can spot errors like this one?
As an alternative, most Python projects are unit tested and system tested. If you have both (or even just unit tests) you’ll find your problem along with pretty much any other issue.
As dekomote said, this is syntaxically valid. Python is not statically typed so this cannot be caught as an error. At most it could be a warning.
EDIT: Python is strongly typed just the type is checked at run time.