PyChecker does STATIC analysis?

beliavsky at aol.com beliavsky at aol.com
Wed Apr 28 11:28:48 EDT 2004


If I run PyChecker on the following program, stored in xtry.py, 

m = 10000000
k = 0
for i in xrange(m):
    k = k + i
print k
x = range(3)
print x[3]

the output is

49999995000000

Warnings...

xtry:1: NOT PROCESSED UNABLE TO IMPORT
Processing xtry...
  Caught exception importing module xtry:
    File "H:\Energy\rao\python\Lib\site-packages\pychecker\checker.py",
line 530, in setupMainCode()
      module = imp.load_module(self.moduleName, file, filename, smt)
    File "xtry.py", line 7
      print x[3]
  IndexError: list index out of range


I am surprised that PyChecker actually needs to execute the code block

for i in xrange(m):
    k = k + i
print k

before finding the out-of-bounds error. I have seen PyChecker
described as a "static analysis" tool, and it does find some problems
that such a tool ought to. But it seems that for the simple program I
have shown, it basically runs the program, and I could just run the
Python program to find the same errors. An aspect of Python
programming that sometimes frustrates me is that a program will run,
perhaps for a few minutes, before stopping because of a misspelled
variable or an out-of-bounds variable. It seems that currently,
PyChecker will not solve this problem. I wish there were a tool that
did (and would be willing to pay for it).

The Lahey/Fujitsu Fortran 95 compiler is able to catch the
out-of-bounds error at COMPILE time for an analogous Fortran program.



More information about the Python-list mailing list