[Python-Dev] 2.2a1 patch from PyChecker

Neal Norwitz neal@metaslash.com
Fri, 10 Aug 2001 11:17:56 -0400


Guido van Rossum wrote:

> > I have changed many unused locals to _ (e.g., for _ in range(3):).
> > This gets PyChecker to shut up about being unused.  It also defaults
> > to ignoring unused local variables if their name is 'empty' or 'unused'.
> 
> Argh!  I don't like using '_' for this, because '_' is already a
> special built-in in interactive mode.  I don't even like the fact that
> PyChecker warns about unused loop control variables at all -- I see
> nothing wrong with code like
> 
>     for i in range(10): print "X"
> 
> and I would rather not have to write it differently specifically to
> shut up PyChecker.  (In general, I find it annoying when a tool like
> this requires one to change one's perfectly fine coding style because
> of a blind spot in the tool. :-)

Agreed.  I try to warn about things that people may care about.

> I'd be happy if there was an option "complain if a loop control
> variable is not used" but it was off by default.

I looked at adding this check, but decided against it initially.
I'll think about adding it.

> > Should the default unused names be expanded?
> 
> I tend to use "dummy" when I need a dummy variable.  But even in tuple

I added 'dummy' as another variable name to ignore if unused.

> unpacks, I prefer to give all variables meaningful names even if I
> don't use all.  To me, this:
> 
>     firstname, lastname, address, phone = get_employee()
> 
> is more readable than this:
> 
>     firstname, lastname, dummy, dummy = get_employee()

I agree, in fact, the first line with real names, does not warn by default.
There is an option to warn if address and phone are unused, -t/--tuple,
but it must be manually enabled.

> > Note:  I could not run under Python 2.2a1 because dir([]) does not
> > return the methods.
> 
> But you can treat it as an instance, and get the methods by looking at
> [].__class__.__dict__.  Read PEP 252 -- it explains how the
> introspection interface will be rationalized.

Ok, I'll take a look.

> > imaplib.py:1026: No global (j) found
> 
> Huh?  There's no 'j' on that line.

I have:

 1025: l = map(lambda x:'%s: "%s"' % (x[0], x[1][0] and '" "'.join(x[1]) or ''
), l)
 1026: _mesg('untagged responses dump:%s%s' % (t, j(l, t)))
                                                  ^^^^^^^

> > pdb.py:138: Overriden method (default) doesn't match signature in
> > class (cmd.Cmd)
> 
> This one I don't understand.  BTW, it would be nice if you could also
> mention the file and line number of the other reference.

Good idea.

> But in general: thanks for PyCecker, Neil, and thanks for the patch
> set!

Thanks for the feedback and feel free to make suggestions.

PyChecker is still an experiment at this point, but it seems
that many people have found it useful.  My goal is to make it
as useful as possible and help promote the use of python
(or eliminate bogus complaints about python, like type checking, etc).

Neal