python improvements (Was: Re: New Language)

Andrew Dalke dalke at acm.org
Sat May 13 00:10:34 EDT 2000


Martijn Faassen wrote:
> How exactly would [an equivalent to perl's "use strict" pragma] work?
> It would seem hard to make this work right in a dynamic language, but
> perhaps I'm missing some simple strategies. I'm not familiar enough
> with 'use strict' in Perl to know what Perl is doing in this respect.

It doesn't have to be correct always, just for reasonable cases.
Perl's 'strict' can be wrong too, and for similar reasons.

A version for Python would be like Aaron Watter's kjpylint, which
tells you if a variable is mentioned once, or used before set.  Of
course, it doesn't work for getattr and other tricks.  It also fails
when a function uses a global variable before it's set, since it
doesn't do call analysis, and it doesn't understand lambdas.

The current version uses the 1.4 syntax so some code will trip it up.
I sent Aaron a patch for that, but I don't think it's been integrated
into kjpylint yet.  Other solutions might be to use the SPARK grammer
for Python or scan the bytecode for which locals and globals are used.
Or modify the Python parser to keep track of all variable references
and do the same logic, which was the original request.

                    Andrew
                    dalke at acm.org








More information about the Python-list mailing list