473,569 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PyChecker messages


Hello,

I take PyChecker partly as an recommender of good coding practice, but I
cannot make sense of some of the messages. For example:

runner.py:878: Function (main) has too many lines (201)

What does this mean? Cannot functions be large? Or is it simply an advice that
functions should be small and simple?
runner.py:200: Function (detectMimeType ) has too many returns (11)

The function is simply a long "else-if" clause, branching out to different
return statements. What's wrong? It's simply a "probably ugly code" advice?
A common message is these:

runner.py:41: Parameter (frame) not used

But I'm wondering if there's cases where this cannot be avoided. For example,
this signal handler:

#-------------------------------------------
def signalSilencer( signal, frame ):
"""
Dummy signal handler for avoiding ugly
tracebacks when the user presses CTRL+C.
"""
print "Received signal", str(signal) + ", exiting."
sys.exit(1)
#-------------------------------------------

_must_ take two arguments; is there any way that I can make 'frame' go away?
Also, another newbie question: How does one make a string stretch over several
lines in the source code? Is this the proper way?

print "asda asda asda asda asda asda " \
"asda asda asda asda asda asda " \
"asda asda asda asda asda asda"
Thanks in advance,

Frans

PS. Any idea how to convert any common time type to W3C XML Schema datatype
duration?
Jul 18 '05 #1
8 2077
Frans Englich wrote:
Also, another newbie question: How does one make a string stretch over several
lines in the source code? Is this the proper way?
(1) print "asda asda asda asda asda asda " \
"asda asda asda asda asda asda " \
"asda asda asda asda asda asda"


A couple of other options here:

(2)
print """asda asda asda asda asda asda
asda asda asda asda asda asda
asda asda asda asda asda asda"""

(3)
print """\
asda asda asda asda asda asda
asda asda asda asda asda asda
asda asda asda asda asda asda"""

(4)
print ("asda asda asda asda asda asda "
"asda asda asda asda asda asda "
"asda asda asda asda asda asda")

Note that backslash continuations (1) are on Guido's list of "Python
Regrets", so it's likely they'll disappear with Python 3.0 (Of course
this is 3-5 years off.)

I typically use either (3) or (4), but of course the final choice is up
to you.

Steve
Jul 18 '05 #2
> runner.py:878: Function (main) has too many lines (201)

What does this mean? Cannot functions be large? Or is it simply an advice that
functions should be small and simple?
It is advice.
runner.py:200: Function (detectMimeType ) has too many returns (11)

The function is simply a long "else-if" clause, branching out to different
return statements. What's wrong? It's simply a "probably ugly code" advice?
That is also advice. Generally you use a dict of functions, or some other
structure to lookup what you want to do.
_must_ take two arguments; is there any way that I can make 'frame' go away?
Yes, you can name it just _ (underscore). There are a few other names like
that that are ignored. (Check the doc).
Also, another newbie question: How does one make a string stretch over several
lines in the source code? Is this the proper way?

print "asda asda asda asda asda asda " \
"asda asda asda asda asda asda " \
"asda asda asda asda asda asda"


Depends what you are trying to achieve. Look at triple quoting as well.

Roger
Jul 18 '05 #3
Frans Englich wrote:
Hello,

I take PyChecker partly as an recommender of good coding practice, but I
cannot make sense of some of the messages. For example:

runner.py:878: Function (main) has too many lines (201)

What does this mean? Cannot functions be large? Or is it simply an advice that
functions should be small and simple?
This is an advice. You can set the number after which the warning is triggered
via the maxLines option in your .pycheckrc file.
runner.py:200: Function (detectMimeType ) has too many returns (11)

The function is simply a long "else-if" clause, branching out to different
return statements. What's wrong? It's simply a "probably ugly code" advice?
Same thing; the corresponding option in .pycheckrc is maxReturns. Other options
that may interest you are maxBranches, maxArgs, maxLocals and maxReferences.
Please see PyChecker's documentation for more details.
A common message is these:

runner.py:41: Parameter (frame) not used

But I'm wondering if there's cases where this cannot be avoided. For example,
this signal handler:

#-------------------------------------------
def signalSilencer( signal, frame ):
"""
Dummy signal handler for avoiding ugly
tracebacks when the user presses CTRL+C.
"""
print "Received signal", str(signal) + ", exiting."
sys.exit(1)
#-------------------------------------------

_must_ take two arguments; is there any way that I can make 'frame' go away?


See/set the unusedNames option in .pycheckrc; this is a list of names for which
this kind of warnings are not triggered. If you set for example:

unusedNames = [ 'dummy' ]

in .pycheckrc and if you define your function with:

def signalSilencer( signal, dummy):
...

the warning will not be triggered.

BTW, if your signal handler is just here to catch Ctrl-C, you'd better do a
try/except on KeyboardInterru pt...

HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
Jul 18 '05 #4
On Tue, 11 Jan 2005 06:54:54 +0000, Frans Englich wrote:
Hello,
Hi
I take PyChecker partly as an recommender of good coding practice


You may alos be interested by Pylint [1].

Pylint is less advanced in bug detection than pychecker, but imho its good
coding practice detection is more advanced and configurable (as the pylint
author, i'm a little biased... ;), including naming conventions, code
duplication, bad code smells, presence of docstring, etc...
Side note : I wish that at some point we stop duplicated effort between
pylint and pychecker. In my opinion that would be nice if each one focus
on its strenghs (as i said bugs detection for pychecker and convention
violation / bad code smell for pylint). That would be even better if both
tools could be merged in one, but (at least last time I took a look at
pychecker) the internal architecture is so different that it's not an easy
task today. Any thoughts ?

[1] http://www.logilab.org/projects/pylint

--
Sylvain Thénault LOGILAB, Paris (France).

http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Jul 18 '05 #5
In article <lq************ @home.rogerbinn s.com>,
Roger Binns <ro****@rogerbi nns.com> wrote:
Jul 18 '05 #6
But you could use a dict of return values, or even just assigning a
different return value in each if clause. The end result is that you
have a single well-defined exit point from the function, which is
generally considered to be preferable.

Jul 18 '05 #7
"Ben Sizer" <ky*****@gmail. com> wrote in message
news:11******** *************@c 13g2000cwb.goog legroups.com...
But you could use a dict of return values, or even just assigning a
different return value in each if clause. The end result is that you
have a single well-defined exit point from the function, which is
generally considered to be preferable.
Preferable, but not any form of an absolute. "Single Exit"
was one of the recommendations from the early structured
program work back in the 70s, and the industry has long
since sent it to the dustbin of history.

The issue is a simple one of clarity, and woodenly applying
the single exit rule where it doesn't belong frequently
winds up creating nested if-elif-else structures and extranious
flag variables.

If an embedded return isn't clear, the method probably
needs to be refactored with "extract method" a few
times until it is clear.

John Roth


Jul 18 '05 #8
In article <11************ *********@c13g2 000cwb.googlegr oups.com>,
Ben Sizer <ky*****@gmail. com> wrote:
But you could use a dict of return values, or even just assigning a
different return value in each if clause. The end result is that you
have a single well-defined exit point from the function, which is
generally considered to be preferable.


Well, no; I'm trying to say exactly that there are times when "a dict
of return values" only adds complexity. Or perhaps I'm missing a bet-
way to code:

def condition_label ():
if x13.fluid_level () > lower_threshhol d:
return "OK"
if user in restricted_list :
return "Ask for help"
if not current_time.in _range(beginnin g, end):
return "Uncorrecta ble exception reported"
...

When conditions live in a space with higher dimensionality than any
handy immutable range, no dict-ification is a benefit.
Jul 18 '05 #9

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

Similar topics

0
1745
by: Pedro Werneck | last post by:
Hi, I don't know if I should ask this here or on an emacs group/list. If I choose wrong, please forgive me. I am trying to run pychecker on the current buffer on python-mode using the py-pychecker-run command, but it fails with the "Symbol's function definition is void: read-shell-command" error. I don't know elisp, but seems this is the...
1
1473
by: Neal Norwitz | last post by:
A new version of PyChecker is (finally) available for your hacking pleasure. It's been quite a while since the last release--11 months. I wish there was more progress, but such is life. Many bug fixes and some new warnings were added. I hope to get future releases out faster. I have several patches queued up and ideas for more warnings. ...
1
1915
by: Jp Calderone | last post by:
When using PyChecker on a project which uses bsddb, dozens of messages like the following are reported: warning: couldn't find real module for class bsddb._db.DBAccessError (module name: bsddb._db) I've looked through the PyChecker usage information, documentation, and browsed some of the source, but I can't find any options for...
6
1432
by: Olaf Meding | last post by:
Is there a way to tell PyChecker to "skip" a line of source code? Or any other workarounds would also greatly appreciated. This line: s = sys.stdin.read(4) Causes this PyChecker error: IOError: Bad file descriptor Thanks much for your help.
4
2251
by: beliavsky | last post by:
If I run PyChecker on the following program, stored in xtry.py, m = 10000000 k = 0 for i in xrange(m): k = k + i print k x = range(3) print x
21
1928
by: Philippe Fremy | last post by:
Hi, I would like to develop a tool that goes one step further than pychecker to ensure python program validity. The idea would be to get close to what people get on ocaml: a static verification of all types of the program, without any kind of variable declaration. This would definitely brings a lot of power to python. The idea is to...
1
1397
by: Neal Norwitz | last post by:
Special thanks to Ken Pronovici. He did a lot of work for this release and helped ensure it occurred. Version 0.8.15 of PyChecker is available. It's been over a year since the last release. Wow, time really does fly. Since it's been so long I'm sure I screwed something up, treat it delicately. It may have bugs and erase your hard...
4
1927
by: Anthony Greene | last post by:
Howdy, I had the impression that pychecker caught and reported such dynamic syntactical errors. #!/usr/bin/env python def add(i): i += 10 status = 3
0
1035
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
0
7703
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...
0
8132
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...
1
7678
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7982
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...
0
6286
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...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3656
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...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2116
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

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.