pychecker question

Neal Norwitz neal at metaslash.com
Thu May 16 12:42:49 EDT 2002


On Mon, 13 May 2002 09:29:46 -0400, Roman Suzi wrote:

> Hi!
> 
> I am pychecking my code and am getting lots of:
> 
> stable.py:210: Variable (path) used before being set 
> stable.py:210: Variable (split) used before being set
> stable.py:224: Variable (strip) used before being set
> stable.py:226: Variable (index) used before being set
> stable.py:261: Variable (join) used before being set
> stable.py:261: Variable (replace) used before being set
> 
> These are caused by from-import statements inside functions,
> schematically:
> 
> def f(x):
>   from m import y
>   return y(x)
> 
> Is it really considered bad to use from-import inside function
> definition? (I did it because I wanted to state clearly which functions

I don't think it is particularly bad.  It could be a bug in pychecker.
Which version of pychecker & python?

> I am using from there. And I do not want to use it at the module level,
> like that:
> 
> from m import y
> def f(x):
>   return y(x)
> 
> as I think it will increase the number of imports.

Actually, this will decrease the number of imports.  This will be done
only once for the whole program.  Whereas if the import occurs within a
function, the byte codes will be executed for each function call.  The
import work (actually reading file, etc) will still only be done once,
regardless of where the import is.

> Another question. Is there any front-end to pychecker to show code in
> proper context and an ability to silence certain warnings just like I do
> in ispell if I consider some word correct?
 
There is a simple GUI which isn't documented:  pychecker/options.py. But
you are probably much better off with an IDE, emacs, boa, or wingide.
(I've only used emacs.)

There are many ways to silence warnings:  using __pychecker__ in your
code, .pycheckrc file, or the command line all work.  Probably the best
way is .pycheckrc.  There is a sample one in the distribution (pycheckrc).
 The main page should have a brief description of most of this info: 
http://pychecker.sf.net.

Neal



More information about the Python-list mailing list