How to detect typos in Python programs

Manish Jethani manish.j at gmx.net
Sun Jul 27 16:02:29 EDT 2003


John J. Lee wrote:

> Manish Jethani <manish.j at gmx.net> writes:
> [...]
> 
>>>The proposed typo catcher would probably catch a typo like
>>>
>>>        sys.edit (5)    # finger didn't get off home row
>>>
>>>but it probably would *NOT* catch
>>>
>>>        sys.exit (56)   # wide finger mashed two keys
>>
>>1)  That's in a different class of typos.  Such things can't be
>>auto-detected in any language.  It will probably require close
>>examination by the human who wrote it in the first place, or
>>someone who has been debugging it.
> 
> 
> That was, indeed, precisely the point that was being made.  Tests can
> catch these, static type analysis can't.

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.

The "56" example is out of place here.  I have fixed the code:

--------
[maybe a constants.py or whatever]
arbit_code = 56

[... elsewhere...]

sys.exit(arbir_code)
--------

That error can be caught in static analysis.

>>2)  No on calls sys.exit() like that.  5, or 56, is probably a
>>constant defined somewhere (where such typos are easier to spot).
> 
> 
> Yes.  Do you have a point?

Yes.  Don't use bad coding practices as an excuse.

-Manish

-- 
Manish Jethani (manish.j at gmx.net)
phone (work) +91-80-51073488





More information about the Python-list mailing list