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. 4 2238 be*******@aol.com wrote: 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.
while there might be not-so-obvious cases that can be found using static
analysis, the halting problem also applies here: There is no such thing as
a automated analysis that finds out if your prgram is going to die or not.
So automatically running a program as part of the analysis is as valid as
any other technique - as long as there are no permantent sideeffects (you
don't want your partitioning code accidentially ruin your hd while
developing...)
Given the fact that nobody prevents you from doing this: xrange = lambda x: [1,2,3,4,5] x = range(3) print x[3]
4
you can fool a static analysis, I wont blame Pychecker too much.
--
Regards,
Diez B. Roggisch
Diez B. Roggisch wrote: xrange = lambda x: [1,2,3,4,5]
Oops - that was supposed to be
range = lambda x: [1,2,3,4,5]
of course... I'm so used to prefering xrange over range, I confused
myself...
--
Regards,
Diez B. Roggisch be*******@aol.com wrote: 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.
You're right but now try on :
def main():
m = 10000000
k = 0
for i in xrange(m):
k = k + i
print k
x = range(3)
print x[3]
if __name__=='__main__':
main()
And it should work !
PyChecker import your file and does not just do a source checking...
--
Yermat
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Pedro Werneck |
last post by:
Hi,
I don't know if I should ask this here or on an emacs group/list. If I choose wrong, please forgive me.
I am trying to run pychecker on the current buffer on python-mode using the...
|
by: Neal Norwitz |
last post by:
A new version of PyChecker is (finally) available for your hacking pleasure.
It's been quite a while since the last release--11 months.
I wish there was more progress, but such is life.
Many bug...
|
by: Stephen Ferg |
last post by:
I've just spent several very frustrating hours tracking down a bug in
one of my programs. The problem was that I was writing text to a
file, and when I was done I coded
f.close
when I should...
|
by: Olaf Meding |
last post by:
What does the below PyChecker warning mean?
More importantly, is there a way to suppress it?
PyChecker warning:
..\src\phaseid\integration.py:21: self is argument in staticmethod
My best...
|
by: Philippe Fremy |
last post by:
Hi,
I would like to develop a tool that goes one step further than pychecker
to ensure python program validity. The idea would be to get close to
what people get on ocaml: a static verification...
|
by: simon.dahlbacka |
last post by:
Hi,
I'm trying to make a decent .pycheckrc for our project and have
stumbled on a few issues. (the pychecker-list would have seemed like
the appropriate place, but the S/N ratio seemed very low...
|
by: Neal Norwitz |
last post by:
Special thanks to Ken Pronovici. He did a lot of work for this
release and helped ensure it occurred.
Version 0.8.15 of PyChecker is available. It's been over a year since
the last release. ...
|
by: Anthony Greene |
last post by:
Howdy, I had the impression that pychecker caught and reported such
dynamic syntactical errors.
#!/usr/bin/env python
def add(i):
i += 10
status = 3
|
by: Edward K. Ream |
last post by:
I am wondering whether anyone knows of a static source-code analyzer for
Python, kinda like a static pychecker.
That is, instead of being a run-time tool as pychecker is, it would be a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |