How to detect typos in Python programs

aj coon ajcoon at hotmail.com
Fri Jul 25 13:54:07 EDT 2003


Manish Jethani <manish.j at gmx.net> wrote in message news:<ZPaUa.6$gZ.133 at news.oracle.com>...
> 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
<filename>', 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




More information about the Python-list mailing list