Syntax checking python...

Andrew Bennetts andrew-pythonlist at puzzling.org
Fri Jan 31 19:14:09 EST 2003


On Fri, Jan 31, 2003 at 10:05:48PM +0000, Afanasiy wrote:
> 
> In other languages, I can receive syntax errors without the script having
> to execute. Please do not let this hurt your feelings. I merely bring up
> the other languages as an example of what I mean and what I am used to.
> 
> In Python, I will not receive a syntax error until the interpreter runs
> right into it. This is not very efficient for me during my development.

Actually, you'll receive a SyntaxError as soon as you import a module with
invalid syntax, which is generally very early in the running of your
program.

> Is there a way I can be notified of my typos without having to run the
> interpreter up to those mistakes? That is my question. No smartasses.

Of course, typos cause more than just SyntaxErrors....

    def foo(arg1):
        print agr1

That's syntactically correct, but obviously wrong, and I suspect this is
more the sort of typo you have in mind (SyntaxErrors are rarely a problem if
you use an editor with syntax highlighting).  In this case, I've found
PyChecker <http://pychecker.sf.net/> to be extremely effective (and it'll
tell you about plain SyntaxErrors as well).

PyChecker is remarkably good at finding most of the typos that I make.  Its
biggest drawbacks for me are:
  - it still throws a fair few false positives
  - it can't cope with Zope's extension classes, or something, meaning I
    can't use it to check my Zope products that I develop at work.

Despite that, I still use it regularly, because it is so handy.  Hopefully
it solves your problem too.

Regards,

-Andrew.






More information about the Python-list mailing list