python "syntax-checker"?

Alex Martelli aleaxit at yahoo.com
Mon Sep 11 03:56:32 EDT 2000


<s_gherman at yahoo.com> wrote in message news:8phlrn$4iu$1 at nnrp1.deja.com...
> Is there any tool out there that would perform a "syntax-checking" on a
> Python source code?

Yes, and it's called "the Python compiler".  Whenever you compile a
Python source file, it is fully syntax-checked.


> Or, even more, to _simulate_ running and type-binding errors, etc (as
> compiler does for C, for instance)?

Not as far as I know, and it does not seem theoretically feasible, as
Python is too fluid & dynamic.  Some heuristic checking, as *lint* did
for C, is possible; there are indeed lint-like tools for Python.  See,
for example, this group of Tim Peters posts...:
ftp://ftp.gigabell.net/pub/python-patches/tim_one/000408.html
ftp://ftp.gigabell.net/pub/python-patches/tim_one/000409.html
ftp://ftp.gigabell.net/pub/python-patches/tim_one/000414.html
ftp://ftp.gigabell.net/pub/python-patches/tim_one/000419.html

or for a completed, working, simple thing, Ka-Ping Yee's pylint:
http://www.lfw.org/python/pylint

or the kjpylint.py that comes with Aaron Watters' kwParser:
http://www.chordate.com/kwParsing/


These, I believe, are all pretty old, from '97 or so; I don't
know how they would react to a Python program fully using today's
syntax &c.  These tools don't seem to attract much practical,
continuing interest, after the first blush thereof.

One more recent effort, by Scott Hassan and David Jeske, can
be found at:
http://www.chat.net/~jeske/Projects/PyLint/download/
with some explanation at:
http://www.deja.com/getdoc.xp?AN=551464214
This is from the end of last year, and it does focus on
type-inference, as you ask.  I'm not sure how much of a
practical tool it would prove, but, it may be worth checking
it up.


> I am not sure to what extent Python's dynamic type nature allows that,
> but I imagine there are some applications where one may not affors to
> half-run them just to find mistakes in the middle of his source code.

Of course there are, and in such cases one organizes one's development
process around the concept of *TESTING*.  There are excellent unit-test
frameworks for Python.  For the general concept, you may want to look
into Extreme Programming (XP), an approach whose inception was based
on Smalltalk but appears to me to be just as suited to Python, although
some useful XP tools are in very early stages for Python (a refactoring
browser, for example; there's a start to that at
    http://bicyclerepair.sourceforge.net/
if you're interested).  For a start on XP, among many other excellent
sites, do look into The Wiki, http://c2.com/cgi-bin/wiki which talks
about many things but does end up mostly about XP and allied subjects,
see http://c2.com/cgi-bin/wiki?ExtremeProgramming.


Alex






More information about the Python-list mailing list