How to detect typos in Python programs

Peter Hansen peter at engcorp.com
Tue Jul 29 07:24:47 EDT 2003


Manish Jethani wrote:
> 
> There's a difference between my "abost()" example and the "56"
> example.  There's no function called abost anywhere in the
> program text, so I should be able to detect the error with
> static analysis.  Even in C, the compiler warns about stray
> function calls.

You don't understand the dynamic nature of Python if you
think this is something that is either easy or 100% reliable.

Very contrived but instructive example:

def func(x):
   pass

import sys
setattr(sys, 'ab' + 'ost', func)

stick-that-in-your-static-analyzer-and-smoke-it-ly y'rs
-Peter




More information about the Python-list mailing list