PyChecker does STATIC analysis?
Skip Montanaro
skip at pobox.com
Wed Apr 28 12:36:29 EDT 2004
beliavsky> If I run PyChecker on the following program, stored in xtry.py,
beliavsky> m = 10000000
beliavsky> k = 0
beliavsky> for i in xrange(m):
beliavsky> k = k + i
beliavsky> print k
beliavsky> x = range(3)
beliavsky> print x[3]
beliavsky> the output is
beliavsky> 49999995000000
beliavsky> Warnings...
beliavsky> xtry:1: NOT PROCESSED UNABLE TO IMPORT
...
beliavsky> I am surprised that PyChecker actually needs to execute the
beliavsky> code block
beliavsky> for i in xrange(m):
beliavsky> k = k + i
beliavsky> print k
beliavsky> before finding the out-of-bounds error.
Try modifying your code to this:
if __name__ == "__main__":
m = 10000000
k = 0
for i in xrange(m):
k = k + i
print k
x = range(3)
print x[3]
PyChecker simply imports your module. Importing a module causes the code at
the top level to be executed.
beliavsky> The Lahey/Fujitsu Fortran 95 compiler is able to catch the
beliavsky> out-of-bounds error at COMPILE time for an analogous Fortran
beliavsky> program.
Python is just slightly more dynamic than Fortran, and I'm sure the
Lahey/Fujitsu compiler has had a few more man-years of development put into
it than PyChecker. As an example of the former point, note that PyChecker
can't assume that the output of range(3) is a list of 3 elements. Another
module may have modified builtins before the code was executed.
Skip
More information about the Python-list
mailing list