Hi all,
Is there a way to detect typos in a Python program, before
actually having to run it. Let''s say I have a function like this:
def server_closed_connection():
session.abost()
Here, abort() is actually misspelt. The only time my program
follows this path is when the server disconnects from its
end--and that''s like once in 100 sessions. So sometimes I
release the program, people start using it, and then someone
reports this typo after 4-5 days of the release (though it''s
trivial to fix manually at the user''s end, or I can give a patch).
How can we detect these kinds of errors at development time?
It''s not practical for me to have a test script that can make
the program go through all (most) the possible code paths.
-Manish
--
Manish Jethani (manish.j at gmx.net)
phone (work) +91-80-51073488
解决方案Manish Jethani wrote:Is there a way to detect typos in a Python program, before
actually having to run it. Let''s say I have a function like this:
def server_closed_connection():
session.abost()
Here, abort() is actually misspelt. The only time my program
follows this path is when the server disconnects from its
end--and that''s like once in 100 sessions. So sometimes I
release the program, people start using it, and then someone
reports this typo after 4-5 days of the release (though it''s
trivial to fix manually at the user''s end, or I can give a patch).
How can we detect these kinds of errors at development time?
It''s not practical for me to have a test script that can make
the program go through all (most) the possible code paths.
You have no good alternative. Why do you say it''s impractical
to actually test your software before it''s shipped? Isn''t it
more impractical to rely on your users to test the software,
thinking it should work?
Unit testing in Python is *really* easy. I can''t think of any
reason not to do it as the best way of catching problems like you
show above. If you resist :-), however, you might find PyChecker
will help. I''m not sure if it can do anything in the above case
yet, however.
-Peter
Manish Jethani a écrit :Hi all,
Is there a way to detect typos in a Python program, before
actually having to run it.
You may want to give a look at pylint (http://www.logilab.org/pylint/)
--
Alexandre Fayolle
LOGILAB, Paris (France).
http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Développement logiciel avancé - Intelligence Artificielle - Formations
Manish Jethani wrote in message news:...Hi all,
Is there a way to detect typos in a Python program, before
actually having to run it. Let''s say I have a function like this:
def server_closed_connection():
session.abost()
Here, abort() is actually misspelt. The only time my program
follows this path is when the server disconnects from its
end--and that''s like once in 100 sessions. So sometimes I
release the program, people start using it, and then someone
reports this typo after 4-5 days of the release (though it''s
trivial to fix manually at the user''s end, or I can give a patch).
How can we detect these kinds of errors at development time?
It''s not practical for me to have a test script that can make
the program go through all (most) the possible code paths.
-Manish
This is one of the things about interpreted languages that I detest-
lack of compile-time errors and warnings. With python, you can
always open an interactive session with the interpreter and ''import
'', but that only catches syntax errors.
For things like unreferenced variables and undefined names (typos, as
you like to nicely put it ;-), theres a program we use for testing our
code:
http://pychecker.sourceforge.net/
Have a look. Admittedly, the information it outputs can be
overwhelming. Take some time to just examine its behaviors and
options. What you''ll probably end up doing is customizing its output,
either by modifying the source, or running it through
grep/awk/sed/python afterwards. But, it''s definitely a starting
point.
-AJ