PyLint results?

Felipe Almeida Lessa felipe.lessa at gmail.com
Fri Apr 21 19:25:13 EDT 2006


Em Sex, 2006-04-21 às 13:49 -0400, Michael Yanowitz escreveu:
>    I ran the new pylint and my code and I had a few questions on why those
> are warnings or what I can do to fix them:

You can ignore the warnings you don't like with the --disable-msg
option. Also, you can add a header to the file to apply a rule just to
it.

> 1) W:  0: Too many lines in module (1587)
>      Why is 1587 considered too many lines? Would there be necessarily be an
>    advantage to split it up into 2 or 3 files? Can I up the limit?

Because Python is terse, and this can be a really large module. Or not.
PyLint is not perfect, maybe you should disable this warning.

> 2) C:  0: Missing required attribute "__revision__"
>    What is this? Is that for CVS? I don't use CVS (we use SVN). I have not
>    seen any sample code which includes this tag yet. But if I include
>    __revision 1.0  somewhere in the code it will remove that warning?

Don't include the variable just to remove the warning -- disable it.

> 3) W:230:readDiscreteData: Using the global statement
>    What is wrong with using the global statement? 

Your code can get unmaintainable if you abuse of it. If you really need
it and know how to use it well, disable the warning. 

> 4) W:261:getDiscreteData: Catch "Exception"
>    What is wrong with that?

You may catch things you don't want to catch, like KeyboardInterrupt
exceptions.

> 5) R:547:readDiscreteData: Too many branches (28/12)
>    Python doesn't have the switch/case statements that C/C++ have. So I
>    could have a large block if/elif/else statements.
>    Is there any way to avoid that?

Only splitting the method into 2 or more parts. If that's not possible,
disable the warning.

> 6) R:722:waitDiscretes: Too many local variables (38/15)
>    That's new to me. What is wrong with too many local variables?
>    Can anything be done to improve that besides having too many globals?

The more local variables you have, the more difficult the code is to
read. Or you use less variables, or you split the method into 2 or more
parts, or you disable the warning.

> 7) W:933:sendStringToSocket: Redefining name 'nPortNumber' from outer scope
> (line
>    What is wrong with using the same variable name in a function that is
> used by its caller?

You are hiding something. For example, this code fails strangely (I know
this example isn't that good, but you get the idea):

files = glob('something/*')
for file in files:
    # do_something 
    filename = do_something_with_the_name(file)
    # do_something_more
    contents = file(filename).read() # fails here

> 8) W:995:sendStringToSocket: Used builtin function 'map'
>    Is that a problem?

Sometimes it's slower than list comprehensions, sometimes it's less
legible than list comp. and IIRC GvR doesn't like it, but if you do,
disable the warning.

HTH,

-- 
Felipe.




More information about the Python-list mailing list