By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,959 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,959 IT Pros & Developers. It's quick & easy.

lint for Python?

P: n/a
Pat
I've been searching for a good multi-module lint checker for Python and
I haven't found one yet.

Pylint does a decent job at checking for errors only within a single module.

Here's one of my problems. I have two modules.

In module one, I have a function:

def foo( host, userid, password ):
pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called
while the program is running. I don't want that error found at 3AM.

I've never used a language that didn't catch that type of error. I'm
quite surprised that Python is being used by a number of major
companies. How you catch these types of errors?

I've spoken to tech support at Wing and they weren't aware of a
multi-module lint but they're considering putting their own lint into
their IDE.

Thank you
Oct 3 '08 #1
Share this Question
Share on Google+
15 Replies


P: n/a
On Fri, Oct 3, 2008 at 2:38 PM, Pat <Pa*@tanker.netwrote:
I've been searching for a good multi-module lint checker for Python and I
haven't found one yet.

Pylint does a decent job at checking for errors only within a single module.

Here's one of my problems. I have two modules.

In module one, I have a function:

def foo( host, userid, password ):
pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called while
the program is running. I don't want that error found at 3AM.

I've never used a language that didn't catch that type of error. I'm quite
surprised that Python is being used by a number of major companies. How you
catch these types of errors?
In a word (or phrase rather): unit testing. Lots of unit testing,
which catches both silly errors like this and more complicated logic
errors.
Check out the 'unittest' module
[http://docs.python.org/library/unittest.html] and any of the many
writings on the subject for more information. And I'm sure some other
posters will respond with more thorough explanations.

Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com
>
I've spoken to tech support at Wing and they weren't aware of a multi-module
lint but they're considering putting their own lint into their IDE.

Thank you
--
http://mail.python.org/mailman/listinfo/python-list
Oct 3 '08 #2

P: n/a
In message <gc**********@aioe.org>, Pat wrote:
In module one, I have a function:

def foo( host, userid, password ):
pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called
while the program is running. I don't want that error found at 3AM.

I've never used a language that didn't catch that type of error.
Because in Python, it's not necessarily an error. Every name you define in
Python is just a variable, and can have its value changed at any time: the
compiler can't tell that foo won't have a different value put into it
between the definition of the function and the actual call.
Oct 4 '08 #3

P: n/a
On Fri, 03 Oct 2008 17:38:13 -0400, Pat wrote:
Pylint does a decent job at checking for errors only within a single
module.

Here's one of my problems. I have two modules.

In module one, I have a function:

def foo( host, userid, password ):
pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called
while the program is running. I don't want that error found at 3AM.
Then don't run the unit tests that late at night (or early in the
morning). ;-)

Besides the `unittest` module from the standard library you might look
into `py.test` and `nose`.

Ciao,
Marc 'BlackJack' Rintsch
Oct 4 '08 #4

P: n/a
Pat:

I know about 3 different lints for Python, there's PyFlake too. But I
don't know if it does what you want.

I've never used a language that didn't catch that type of error.
What dynamic languages have you used in the past?

I'm quite surprised that Python is being used by a number of major
companies. How you catch these types of errors?
Writing tests. You must adapt your coding style to the language you
use.
In Java/C++ your static type system catches those bugs for you, in
dynamic languages you have to catch them with testing (or lints, if
they are present). Languages like Haskell with a type system much
stronger than Java/C++ ones help you catch even more bugs/problems at
compile time, so you need more time to have a clean compilation, but
you have less bugs later (but tests are useful in Haskell too, see
QuickCheck, that has inspired lot of similar tools for other
languages, Python included).

Bye,
bearophile
Oct 4 '08 #5

P: n/a
On Oct 3, 5:38*pm, Pat <P...@tanker.netwrote:
I've been searching for a good multi-module lint checker for Python and
I haven't found one yet.

Pylint does a decent job at checking for errors only within a single module.

Here's one of my problems. *I have two modules.

In module one, I have a function:

def foo( host, userid, password ):
* * *pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called
while the program is running. *I don't want that error found at 3AM.

I've never used a language that didn't catch that type of error. *I'm
quite surprised that Python is being used by a number of major
companies. *How you catch these types of errors?

I've spoken to tech support at Wing and they weren't aware of a
multi-module lint but they're considering putting their own lint into
their IDE.

Thank you
I doubt you will find a tool that can find that kind of error(at least
not reliably), python is a highly dynamic language, and so foo() can
easily be reassigned at any point in the execution.
Oct 4 '08 #6

P: n/a
On Oct 3, 4:38*pm, Pat <P...@tanker.netwrote:
I've been searching for a good multi-module lint checker for Python and
I haven't found one yet.

Pylint does a decent job at checking for errors only within a single module.

Here's one of my problems. *I have two modules.

In module one, I have a function:

def foo( host, userid, password ):
* * *pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called
while the program is running. *I don't want that error found at 3AM.

I've never used a language that didn't catch that type of error. *I'm
quite surprised that Python is being used by a number of major
companies. *How you catch these types of errors?
You have to write extensive tests for your code. Not only does this
catch trivial errors like the above, but it finds logic errors in your
implementation.
>
I've spoken to tech support at Wing and they weren't aware of a
multi-module lint but they're considering putting their own lint into
their IDE.

Thank you
Oct 5 '08 #7

P: n/a
Hello,
In module one, I have a function:

def foo( host, userid, password ):
* * *pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called
while the program is running.
pychecker does find these kind of errors.
I've never used a language that didn't catch that type of error. *I'm
quite surprised that Python is being used by a number of major
companies. *How you catch these types of errors?
By running a large test suite, I highly recommend "nose".

HTH,
--
Miki <mi*********@gmail.com>
http://pythonwise.blogspot.com
Oct 5 '08 #8

P: n/a
Pat
Miki wrote:
Hello,
>In module one, I have a function:

def foo( host, userid, password ):
pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called
while the program is running.
pychecker does find these kind of errors.
Before posting my original question, I tried pychecker and it didn't
catch that error.
>
>I've never used a language that didn't catch that type of error. I'm
quite surprised that Python is being used by a number of major
companies. How you catch these types of errors?
By running a large test suite, I highly recommend "nose".
That's something I'll look into after I'm more proficient in Python.
Currently, I'm learning my way around Python.

Thank you.
>
HTH,
--
Miki <mi*********@gmail.com>
http://pythonwise.blogspot.com
Oct 5 '08 #9

P: n/a
Pat wrote:
I've been searching for a good multi-module lint checker for Python and
I haven't found one yet.

Pylint does a decent job at checking for errors only within a single
module.

Here's one of my problems. I have two modules.

In module one, I have a function:

def foo( host, userid, password ):
pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called
while the program is running. I don't want that error found at 3AM.

I've never used a language that didn't catch that type of error. I'm
quite surprised that Python is being used by a number of major
companies. How you catch these types of errors?

I've spoken to tech support at Wing and they weren't aware of a
multi-module lint but they're considering putting their own lint into
their IDE.

Thank you
--
http://mail.python.org/mailman/listinfo/python-list
The example you gave is specific. You could catch that one by hand.
But, would it hurt, perhaps by causing neglect of other errors; and
would it be worth the effort? And, if you're using any dynamics at all,
catching that one's even in question.

from mod import foo
bar= foo
bar( arg1, arg2 )

It would add difficulty to catching by hand. Same with variable
argument lists.

from mod import foo
args= ( arg1, arg2 )
foo( *args )

If you could knock off an error and ignore the false positives, that
might be worth an afternoon.

Oct 5 '08 #10

P: n/a
Pat wrote:
I've been searching for a good multi-module lint checker for Python and
I haven't found one yet.

Pylint does a decent job at checking for errors only within a single
module.

Here's one of my problems. I have two modules.

In module one, I have a function:

def foo( host, userid, password ):
pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called
while the program is running. I don't want that error found at 3AM.

I've never used a language that didn't catch that type of error. I'm
quite surprised that Python is being used by a number of major
companies. How you catch these types of errors?

I've spoken to tech support at Wing and they weren't aware of a
multi-module lint but they're considering putting their own lint into
their IDE.

Thank you
--
http://mail.python.org/mailman/listinfo/python-list
The example you gave is specific. You could catch that one by hand.
But, would it hurt, perhaps by causing neglect of other errors; and
would it be worth the effort? And, if you're using any dynamics at all,
catching that one's even in question.

from mod import foo
bar= foo
bar( arg1, arg2 )

It would add difficulty to catching by hand. Same with variable
argument lists.

from mod import foo
args= ( arg1, arg2 )
foo( *args )

If you could knock off an error and ignore the false positives, that
might be worth an afternoon.


Oct 5 '08 #11

P: n/a
Pat wrote:
I've been searching for a good multi-module lint checker for Python and
I haven't found one yet.

Pylint does a decent job at checking for errors only within a single
module.

Here's one of my problems. I have two modules.

In module one, I have a function:

def foo( host, userid, password ):
pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called
while the program is running. I don't want that error found at 3AM.

I've never used a language that didn't catch that type of error. I'm
quite surprised that Python is being used by a number of major
companies. How you catch these types of errors?

I've spoken to tech support at Wing and they weren't aware of a
multi-module lint but they're considering putting their own lint into
their IDE.

Thank you
--
http://mail.python.org/mailman/listinfo/python-list
The example you gave is specific. You could catch that one by hand.
But, would it hurt, perhaps by causing neglect of other errors; and
would it be worth the effort? And, if you're using any dynamics at all,
catching that one's even in question.

from mod import foo
bar= foo
bar( arg1, arg2 )

It would add difficulty to catching by hand. Same with variable
argument lists.

from mod import foo
args= ( arg1, arg2 )
foo( *args )

If you could knock off an error and ignore the false positives, that
might be worth an afternoon.


Oct 5 '08 #12

P: n/a
On Oct 5, 8:53*am, Pat <P...@junk.netwrote:
Miki wrote:
Hello,
In module one, I have a function:
def foo( host, userid, password ):
* * *pass
In module two, I call that function:
foo( userid, password)
lint doesn't find that error and it won't be caught until it's called
while the program is running.
pychecker does find these kind of errors.

Before posting my original question, I tried pychecker and it didn't
catch that error.
Sorry for the multiple posting earlier (you heard me right, not 2 but
3 identical). The basic checker of walking a parse tree, doing
imports by hand, and checking call signatures isn't awful. 60 lines.

/File:

from ng23mod1 import foo as foo
userid, password= 'abc', '123'
import random
foo( 'localhost', userid, password)
if random.uniform( 0, 1 )< .01: # 1 out of 100 times
foo( userid, password)

/Checker output:

foo ['Str', 'Name', 'Name'] found 3 expected
random ['Num', 'Num'] found 2 expected
foo ['Name', 'Name'] found 3 expected

But it's extremely delicate and at 60 lines only checks fixed-length
call signatures and functions, not even methods. If you have a
statement:

x= y.z()

Then 'y' has to be defined somewhere, so you could make some educated
guesses that way.
Oct 6 '08 #13

P: n/a
No need to develop another lint tool. Just give the creator of pylint an
improvement proposal. This can be at least reported as a warning.

Even in a highly dynamic language like Python it is good to follow some
style guides. I try to avoid the same names if possible for different
functionality. This makes the code much more manageable and maintainable
and understandable for larger projects.

Pat schrieb:
I've been searching for a good multi-module lint checker for Python and
I haven't found one yet.

Pylint does a decent job at checking for errors only within a single
module.

Here's one of my problems. I have two modules.

In module one, I have a function:

def foo( host, userid, password ):
pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called
while the program is running. I don't want that error found at 3AM.

I've never used a language that didn't catch that type of error. I'm
quite surprised that Python is being used by a number of major
companies. How you catch these types of errors?

I've spoken to tech support at Wing and they weren't aware of a
multi-module lint but they're considering putting their own lint into
their IDE.

Thank you
Oct 6 '08 #14

P: n/a
Pat
Bruno Desthuilliers wrote:
Pat a écrit :
>I've been searching for a good multi-module lint checker for Python
and I haven't found one yet.

Pylint does a decent job at checking for errors only within a single
module.

Here's one of my problems. I have two modules.

In module one, I have a function:

def foo( host, userid, password ):
pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error

Nope, but even the most simple manual test should find it pretty quick.
>and it won't be caught until it's called while the program is
running. I don't want that error found at 3AM.

Don't you ever test your code ???
>I've never used a language that didn't catch that type of error.

It does. Just try to run your code, and you'll have a nice traceback.
Unless of course 'foo' is rebound in module two to another callable
expecting only two parameters...
> I'm quite surprised that Python is being used by a number of major
companies.

Perhaps do they rely more on testing and less on the compiler ? FWIW,
I've seen my share of bugs in declarativly statically typed languages,
and most of them were way nastier (and way less obvious) than the above
one.
> How you catch these types of errors?

Just like any other type of errors : testing, testing, and then add some
more tests.
I haven't gotten into unittesting. I've just started learning Python.

It also dawned on me why my original question is a bit lame. Python
supports default arguments; something that is new to me. How could lint
possibly know the correct number of arguments passed to it? Unless, of
course, lint knew which functions had default arguments or not.

I'll come back with more intelligent questions after I've actually
learned some Python.
Oct 6 '08 #15

P: n/a
On Oct 6, 3:49 pm, Pat <P...@junk.comwrote:
I'll come back with more intelligent questions after I've actually
learned some Python.
That's a wise self-advice ;-)
Oct 6 '08 #16

This discussion thread is closed

Replies have been disabled for this discussion.