Re: PyLint results?

2006-04-25 Thread Alexandre Fayolle

Others have answered most of your questions, I won't repeat the answers
here, but only join the choir to stress that pylint needs tuning to
your coding style. An obvious case is camelCaseMethodNames versus
underscored_method_names, but there are also a lot of issues. The
default pylint settings match Logilab's coding standards. The coding
metrics were heavily inspired by Steve McConnell's Code Complete book,
but the figures provided therein have been heavily downscaled to match
for Python's expressivity (Code Complete deals mostly with C/C++/Java
code). 

Le 21-04-2006, Michael [EMAIL PROTECTED] nous disait:

 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?


We generally have a 
__revision__ = '$Id$' 

statement at module top level, which gets replaced a check in time by
CVS, which makes it easy to know who checked in the HEAD revision of the
module. This behaviour can be emulated with subversion properties. 



 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?

 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?

For these two, I strongly recommend giving a look at Martin Fowler's
Refactoring book (published by Addison Wesley). These are typical so
called code smells which can be solved using for instance the Extract
Method refactoring.

Of course, it all depends on the kind of program you are working, and
sometimes using intermediate variables helps understanding the code (by
providing useful names, for instance). What pylint tells you is there
could be an issue here, you should check.


-- 
Alexandre Fayolle  LOGILAB, Paris (France).
http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org
-- 
http://mail.python.org/mailman/listinfo/python-list


PyLint results?

2006-04-21 Thread Michael Yanowitz
Hello:

   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:

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?

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?

3) W:230:readDiscreteData: Using the global statement
   What is wrong with using the global statement? I know the use of Globals
   should be discouraged, but often they can't be avoided.
   Suppose I have a constant. In C or C++, I could just use a #define and
   it would be known throughout the whole file. In Python, there isn't a
   similar construct, so rather than creating a large parameter list, of
   constants, I like to use globals.

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

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?

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?

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?

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

  Plus many other warnings about my naming convention or unused variables
which I will ignore
at this time.

  I did find it to be a very useful too any how in cleaning up my code.
I raised my code rate from about -8 to about +7.

Thanks:
Michael Yanowitz









-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyLint results?

2006-04-21 Thread Alexis Roda
Michael Yanowitz escribió:
 Hello:
 
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:
 

 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?

try it and see what happens

 3) W:230:readDiscreteData: Using the global statement
What is wrong with using the global statement? I know the use of Globals
should be discouraged, but often they can't be avoided.
Suppose I have a constant. In C or C++, I could just use a #define and
it would be known throughout the whole file. In Python, there isn't a
similar construct, so rather than creating a large parameter list, of
constants, I like to use globals.

* define all your constants in a separate module constants.py, then:

 from constants import *

* add the constants to __builtins__

 __builtins__.constant_name = value

   this approach is a bit tricky


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

cause you're masquerading *all* exceptions, this could be potentially 
dangerous

 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?

too many local variables probably means too complex function, split it 
in smaller functions

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyLint results?

2006-04-21 Thread André Malo
* Michael Yanowitz wrote:

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:
 
 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?

not necessarily. It might be considered bad style to put too much stuff into
one module. This depends on the content. You can now raise the limit (which
is 1000 lines by default) with the --max-module-lines command line option
or using a config file (generate one with pylint --generate-rcfile, use it
with pylint --rcfile=filename).

Alternatively you can disable the message for this module by putting
# pylint: disable-msg = Wid
on the top (after the # -*- coding -*- line, if any).
The new pylint allows for local disabling also such comments within the
code.

The id can you get if you enable them in the output via cmdline or config
file.

 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?

yeah. But you can list these attributes in the config... ;-)

 3) W:230:readDiscreteData: Using the global statement
What is wrong with using the global statement? I know the use of
Globals should be discouraged, but often they can't be avoided.
Suppose I have a constant. In C or C++, I could just use a #define and
it would be known throughout the whole file. In Python, there isn't a
similar construct, so rather than creating a large parameter list, of
constants, I like to use globals.

Consider *writing* globals from inside a function as bad style.

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

Typically you do want be more specific, because Exception catches too much.

 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?

Not always. But usually you can restructure your code better (Use more
functions/methods, structure them semantically).

 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?

One could loose the overview, I guess. 38 local variables are really a lot.
Structure your code :)

 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?

It might confuse someone else or you in half a year when reading the code
again.

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

Not really. You might consider using list comprehensions, though.

   Plus many other warnings about my naming convention or unused variables
 which I will ignore
 at this time.
 
   I did find it to be a very useful too any how in cleaning up my code.
 I raised my code rate from about -8 to about +7.

I personally find the code rate nonsense, YMMV ;-)

Note that all messages from pylint should be taken as hints, not a final
verdict. Think about them (you did, as you asked here ;-). Either correct
or ignore them (typically done by locally or even globally disabling them).

Do some fine-tuning using a config matching your own requirements. The
defaults are, well, just defaults.

nd
-- 
die (eval q-qq[Just Another Perl Hacker
]
;-)
# André Malo, http://pub.perlig.de/ #
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: PyLint results?

2006-04-21 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Michael
Yanowitz wrote:

 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?

AFAIK that's a requirement at Logilab.  They use the tool themselves.  :-)

 3) W:230:readDiscreteData: Using the global statement
What is wrong with using the global statement? I know the use of Globals
should be discouraged, but often they can't be avoided.

I guess more often than you think.

Suppose I have a constant. In C or C++, I could just use a #define and
it would be known throughout the whole file. In Python, there isn't a
similar construct, so rather than creating a large parameter list, of
constants, I like to use globals.

If they are constants then you don't rebind them from within functions or
methods, right?  Then you don't need ``global``.  This works without
problems::

 ANSWER = 42

 def spam():
 print ANSWER


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

It catches *any* exception.  For example `KeyboardInterrupt` which can
lead to programs that can't be stopped with CTRL+C or `ZeroDivisionError`
or `NameError` so programming errors are silenced.

 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?

One idiom is to create a dictionary with the values to switch on mapped
to callables to handle the case.

 6) R:722:waitDiscretes: Too many local variables (38/15)
That's new to me. What is wrong with too many local variables?

Well, they are just to many.  :-)

 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?

It's not used by the caller but in the outer scope.  It may confuse the
reader seeing `ham` in the outer scope and then `ham` in the function
without noticing that this is actually another `ham`.

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

`map` is deprecated in favor of list comprehensions.  A matter of taste…

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: PyLint results?

2006-04-21 Thread Felipe Almeida Lessa
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.

-- 
http://mail.python.org/mailman/listinfo/python-list