473,666 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PyLint results?

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:readDiscr eteData: 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:getDiscre teData: Catch "Exception"
What is wrong with that?

5) R:547:readDiscr eteData: 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:waitDiscr etes: 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:sendStrin gToSocket: 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:sendStrin gToSocket: 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



Apr 21 '06 #1
4 5004
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:readDiscr eteData: 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__.co nstant_name = value

this approach is a bit tricky

4) W:261:getDiscre teData: Catch "Exception"
What is wrong with that?
cause you're masquerading *all* exceptions, this could be potentially
dangerous
6) R:722:waitDiscr etes: 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"

Apr 21 '06 #2
* 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 stuffinto
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, useit
with pylint --rcfile=<filenam e>).

Alternatively you can disable the message for this module by putting
# pylint: disable-msg = W<id>
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:readDiscr eteData: 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 #defineand
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:getDiscre teData: Catch "Exception"
What is wrong with that?
Typically you do want be more specific, because Exception catches too much.
5) R:547:readDiscr eteData: Too many branches (28/12)
Python doesn't have the switch/case statements that C/C++ have. SoI
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:waitDiscr etes: 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:sendStrin gToSocket: Redefining name 'nPortNumber' from outer
scope (line
What is wrong with using the same variable name in a function thatis
used by its caller?
It might confuse someone else or you in half a year when reading the code
again.
8) W:995:sendStrin gToSocket: 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/> #
Apr 21 '06 #3
In <ma************ *************** ************@py thon.org>, 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:readDiscr eteData: 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:getDiscre teData: Catch "Exception"
What is wrong with that?
It catches *any* exception. For example `KeyboardInterr upt` which can
lead to programs that can't be stopped with CTRL+C or `ZeroDivisionEr ror`
or `NameError` so programming errors are silenced.
5) R:547:readDiscr eteData: 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:waitDiscr etes: 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:sendStrin gToSocket: 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:sendStrin gToSocket: Used builtin function 'map'
Is that a problem?


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

Ciao,
Marc 'BlackJack' Rintsch
Apr 21 '06 #4

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 camelCaseMethod Names versus
underscored_met hod_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 <m.********@kea rfott.com> 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:readDiscr eteData: 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:waitDiscr etes: 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
Apr 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1223
by: Fried Egg | last post by:
* Codetag PEP: ** I would like to comment on the codetags PEP, which I give a 0+. I think the end "<>" is bad; I would be in favor of a block system or something that looks more like regular Python (e.g. "# :FIXME(line_count=10, date='2005-08-09', ...) "). ** As to the comments that say "Trac does the same functionality" or "Eclipse/Eric/Emacs... has the same functionality" I think codetags are orthogonal to that. Also, some of us...
5
11142
by: Tuomas | last post by:
#!/usr/bin/python """test pydev_0.9.3/../pylint""" __revision__ = "test_mod 0.1 by TV 06/10/22" lst = lst = map(lambda x: x.strip(), lst) result = """ No config file found, using default configuration ************* Module test_mod
7
1794
by: montyphyton | last post by:
Some recent posts about Python programming style got me thinking. Since we have the PEP 8 which gives some guidelines about the style to be used, do we have any program that can check for violations of these guidelines within the source code? I understand that there are a lot of code beautifiers out there, but i haven't seen one specially tailored for Python... Is there even a desire in Python community for a program like this (by Python...
2
1279
by: lgfang | last post by:
Hi, I think this is a bug of pylint.el. But I failed finding a way to submit the bug neither in its official site nor in google. So I post it here wishing it may be useful for some buddies. The bug is that it uses "compile-internal" from "compile" without require compile. So "M-x pylint" will fail if compile hadn't been loaded in advance by any means.
2
2855
by: Mick Charles Beaver | last post by:
Hello, I've been looking into using PyLint on some of my programs, just as a best practices kind of thing. Here's a snippet: #====================================================================== if __name__ == '__main__': parser = optparse.OptionParser(usage='usage: %prog ') parser.add_option('-c', '--config',
0
1040
by: KLEIN Stephane | last post by:
Hi, I wonder if pychecker projet is dead ? On pychecker home page (http://pychecker.sourceforge.net/), last version date from February 3, 2006 and their mailist contain spam messages only. Other tools like pychecker is pylint at (http://www.logilab.org/project/eid/857). This is a great tools and it's still
2
3368
by: dmitrey | last post by:
Hi all, I have Eric 4.1.1, pylint and Eric pylint plugin installed, but I cannot find how to use pylint from Eric IDE GUI. Does anyone know? Thank you in advance, D.
1
222
by: Stefan Rank | last post by:
on 31.07.2008 11:29 Diez B. Roggisch said the following: <snip> <snip> Three installations of pylint 0.14.0 that I have access to from here: pylint.bat 0.14.0, astng 0.17.2, common 0.27.0 Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45)
2
12336
by: GHUM | last post by:
Hello, I am pylinting some software of mine. Now pylint throws messages, and I know of pylint --help-msg to get some more text. What is missing out are explanation, WHY some things are bad, so I am searching for explanations and ways to improve my code: Example:
0
8445
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.