FAQ
PyChecker is a python source code checking tool to help you find common bugs. It is meant to find problems that are
typically caught by a compiler. Because of the dynamic nature of python, some warnings may be incorrect; however,
spurious warnings should be fairly infrequent.

Types of problems that can currently, be found include:

* No doc strings in modules, classes, functions, and methods
* self not the first parameter to a method
* Wrong number of parameters passed to functions/methods
* No global found (e.g., using a module without importing it)
* Global not used (module or variable)

PyChecker currently runs on Python 2.0. If there's interest, it can be back ported to Python 1.5.2.

I have run PyChecker against Python 2.1b2a, the following are problems found in the standard python modules:

### Warnings
codeop.py:3 Imported module (sys) not used
codeop.py:4 Imported module (traceback) not used
fileinput.py:292 Function (input) doesn't require named arguments
multifile.py:30 Imported module (sys) not used
pipes.py:62 Imported module (sys) not used
urllib.py:598 Function (quote) doesn't require named arguments
urllib.py:611 Function (quote) doesn't require named arguments
string.py:190 Variable (_StringType) not used
tabnanny.py:15 Imported module (string) not used
imported again @ 241 and used there

### Errors:
audiodev.py:214 No global (BUFFERSIZE) found
bdb.py:111 No method (do_clear) found
chunk.py:109 No attribute (chunk_size) found
should be chunksize
locale.py:253 No global (l) found
netrc.py:13 No global (file) found
pydoc.py:1070 No global (DocImportError) found
pydoc.py:1070 No global (filename) found


PyChecker is available on Source Forge:
web page: http://pychecker.sourceforge.net/
project page: http://sourceforge.net/projects/pychecker/

Enjoy! Feedback is greatly appreciated.

Neal
--
pychecker at metaslash.com

Search Discussions

  • Neal Norwitz at Apr 7, 2001 at 6:28 pm
    PyChecker is a python source code checking tool to help you find common bugs. It is meant to find problems that are
    typically caught by a compiler. Because of the dynamic nature of python, some warnings may be incorrect; however,
    spurious warnings should be fairly infrequent.

    Types of problems that can currently, be found include:

    * No doc strings in modules, classes, functions, and methods
    * self not the first parameter to a method
    * Wrong number of parameters passed to functions/methods
    * No global found (e.g., using a module without importing it)
    * Global not used (module or variable)

    PyChecker currently runs on Python 2.0. If there's interest, it can be back ported to Python 1.5.2.

    I have run PyChecker against Python 2.1b2a, the following are problems found in the standard python modules:

    ### Warnings
    codeop.py:3 Imported module (sys) not used
    codeop.py:4 Imported module (traceback) not used
    fileinput.py:292 Function (input) doesn't require named arguments
    multifile.py:30 Imported module (sys) not used
    pipes.py:62 Imported module (sys) not used
    urllib.py:598 Function (quote) doesn't require named arguments
    urllib.py:611 Function (quote) doesn't require named arguments
    string.py:190 Variable (_StringType) not used
    tabnanny.py:15 Imported module (string) not used
    imported again @ 241 and used there

    ### Errors:
    audiodev.py:214 No global (BUFFERSIZE) found
    bdb.py:111 No method (do_clear) found
    chunk.py:109 No attribute (chunk_size) found
    should be chunksize
    locale.py:253 No global (l) found
    netrc.py:13 No global (file) found
    pydoc.py:1070 No global (DocImportError) found
    pydoc.py:1070 No global (filename) found


    PyChecker is available on Source Forge:
    web page: http://pychecker.sourceforge.net/
    project page: http://sourceforge.net/projects/pychecker/

    Enjoy! Feedback is greatly appreciated.

    Neal
    --
    pychecker at metaslash.com
  • Pete Shinners at Apr 7, 2001 at 10:10 pm
    "Neal Norwitz" <neal at metaslash.com> wrote
    PyChecker is a python source code checking tool to help you find common
    bugs. It is meant to find problems that are typically caught by a
    compiler. Because of the dynamic nature of python, some warnings may be
    incorrect; however, spurious warnings should be fairly infrequent.
    amazing. this is just great. i hope once it matures we can see
    it included in the standard python distributions (2.2!)

    thanks neal, this is something i've been wanting since my
    first days with python.
  • Robin Becker at Apr 8, 2001 at 12:30 am
    In article <mailman.986668153.19972.python-list at python.org>, Neal
    Norwitz <neal at metaslash.com> writes
    PyChecker is a python source code checking tool to help you find common bugs. It
    is meant to find problems that are
    typically caught by a compiler. Because of the dynamic nature of python, some
    warnings may be incorrect; however, ....
    orge.net/projects/pychecker/

    Enjoy! Feedback is greatly appreciated.
    Well I just checked SF and see no files in CVS and no released files and
    no downloads. Where should I be looking?
    Neal
    --
    pychecker at metaslash.com
    --
    Robin Becker
  • David Lees at Apr 8, 2001 at 5:02 am
    It does not seem to be at sourceforge, but it is at
    http://pychecker.sourceforge.net/ and you click on 'current version'

    Looks useful, but the first thing I tried running it on is some threaded
    socket code and checker.py seems to hang. I think it is trying to run
    the code, which is a problem, because it is not located on the right
    machine for running. I tried both from a DOS window in Win98SE using
    Python 2.0 and also with PythonWin.

    david lees


    Robin Becker wrote:
    In article <mailman.986668153.19972.python-list at python.org>, Neal
    Norwitz <neal at metaslash.com> writes
    PyChecker is a python source code checking tool to help you find common bugs. It
    is meant to find problems that are
    typically caught by a compiler. Because of the dynamic nature of python, some
    warnings may be incorrect; however, ....
    orge.net/projects/pychecker/

    Enjoy! Feedback is greatly appreciated.
    Well I just checked SF and see no files in CVS and no released files and
    no downloads. Where should I be looking?
    Neal
    --
    pychecker at metaslash.com
    --
    Robin Becker
  • Neal Norwitz at Apr 9, 2001 at 1:44 am

    David Lees wrote:

    Looks useful, but the first thing I tried running it on is some threaded
    socket code and checker.py seems to hang. I think it is trying to run
    the code, which is a problem, because it is not located on the right
    machine for running. I tried both from a DOS window in Win98SE using
    Python 2.0 and also with PythonWin.
    Hmmm. From in the interpretter, can you do import:

    import your_module

    Does that work? If you send me your code or a small subset that
    you are having the problem with, I can take a look.

    Neal
  • David Lees at Apr 9, 2001 at 4:30 am
    Neal,

    You have diagnosed the problem. I wrote this particular code as a
    standalone, command line driven routine that has defaults when no
    arguments are present. So when I import my module it uses defaults,
    which are intended for a linux box at work, not the Win98 box at home
    and it hangs. Clearly sloppyness on my part. I need to do some error
    checking.

    David Lees

    Neal Norwitz wrote:
    David Lees wrote:
    Looks useful, but the first thing I tried running it on is some threaded
    socket code and checker.py seems to hang. I think it is trying to run
    the code, which is a problem, because it is not located on the right
    machine for running. I tried both from a DOS window in Win98SE using
    Python 2.0 and also with PythonWin.
    Hmmm. From in the interpretter, can you do import:

    import your_module

    Does that work? If you send me your code or a small subset that
    you are having the problem with, I can take a look.

    Neal
  • Andrew Kuchling at Apr 9, 2001 at 2:03 pm

    David Lees <debl at nonospamyytheworld.com> writes:
    You have diagnosed the problem. I wrote this particular code as a
    standalone, command line driven routine that has defaults when no
    arguments are present. So when I import my module it uses defaults,
    which are intended for a linux box at work, not the Win98 box at home
    and it hangs. Clearly sloppyness on my part. I need to do some error
    checking.
    You probably want to add a block like this to run the main-line code;
    it won't get executed when the module is imported by another module.

    if __name__ == '__main__':
    # Invoke your command-line code here
    ...

    Search through the standard library for lots of examples of this
    idiom.

    --amk
  • Robin Becker at Apr 11, 2001 at 8:55 pm
    In article <mailman.986780712.1461.python-list at python.org>, Neal Norwitz <neal at metaslash.com>
    writes
    David Lees wrote:
    Looks useful, but the first thing I tried running it on is some threaded
    socket code and checker.py seems to hang. I think it is trying to run
    the code, which is a problem, because it is not located on the right
    machine for running. I tried both from a DOS window in Win98SE using
    Python 2.0 and also with PythonWin.
    Hmmm. From in the interpretter, can you do import:

    import your_module

    Does that work? If you send me your code or a small subset that
    you are having the problem with, I can take a look.

    Neal
    I get some oddities

    1) I see messages like this
    c:\python\reportlab\graphics\charts\axes.py:588 Base class (reportlab.graphics.charts.axes.Val
    ueAxis) __init__() not called

    when the derived class explicitly calls the base class init. In the above case the line 588
    looks like

    def __init__(self):
    ValueAxis.__init__(self)

    where the class inherits from ValueAxis

    I also see the following

    c:\python\reportlab\graphics\widgetbase.py:0 No __init__() in subclass (LinePl
    otProperties)
    c:\python\reportlab\graphics\widgetbase.py:1 Imported module (time) not used
    c:\python\reportlab\graphics\widgetbase.py:1 Imported module (types) not used

    here the filename widgetbase.py is the name of an imported module the messages seem to refer to
    the importing module (the one actually being tested).

    Still it seems quite useful. Can it do anything with unnecessary

    from M import *
    --
    Robin Becker
  • Neal Norwitz at Apr 12, 2001 at 4:26 am

    Robin Becker wrote:
    I get some oddities

    1) I see messages like this
    c:\python\reportlab\graphics\charts\axes.py:588 Base class
    (reportlab.graphics.charts.axes.ValueAxis) __init__() not called
    There was a bug in 0.1 that caused this to happen. This is handled better
    in 0.2 (current released version). I'm not positive it works in all cases,
    but it is definitely better than before.

    Better yet, get the current version from CVS. There are more
    warnings (at least one I know of, unused local variables)
    that can be generated and there are now command line options.

    Here are the current options that can be specified on the command line:

    Options: Toggle warning for ... [default]
    -s, --doc turn off all warnings for no doc strings
    -m, --moduledoc no module doc strings [on]
    -c, --classdoc no class doc strings [on]
    -f, --funcdoc no function/method doc strings [off]

    -i, --import unused imports [on]
    -l, --local unused local variables, except tuples [on]
    -t, --tuple all unused local variables, including tuples [off]
    -v, --var all unused module variables [off]
    -p, --privatevar unused private module variables [on]

    -d, --debug turn on debugging for checker [off]

    In addition, you should be able to specify python module/package
    names or file names (thanks to Jeff Collins). This should help
    Mac users, I believe.
    Still it seems quite useful. Can it do anything with unnecessary

    from M import *
    It doesn't by default, but if you use the -v option, it does.

    Neal
    --
    Robin Becker
  • Robin Becker at Apr 12, 2001 at 9:11 am
    In article <mailman.987049644.10605.python-list at python.org>, Neal Norwitz <neal at metaslash.com>
    writes
    OK I switched to the CVS latest and it seems better. I'm still getting the messages from
    imported modules rather than the real one ie

    c:\python\reportlab\graphics\widgetbase.py:0 No __init__() in subclass (LinePlotProperties)
    c:\python\reportlab\graphics\widgetbase.py:1 No module doc string

    here widgetbase is imported by lineplot, but the above errors are certainly for linplot.py
    itself.

    I'm also getting a warning about not calling the base class even when I have got
    an apply(BASE.__init__,.....) I suppose this is more difficult than the straight call.
    --
    Robin Becker
  • Neal Norwitz at Apr 12, 2001 at 3:11 pm

    Robin Becker wrote:

    OK I switched to the CVS latest and it seems better.
    That's good.
    I'm still getting the messages from imported modules
    rather than the real one ie

    c:\python\reportlab\graphics\widgetbase.py:0 No __init__()
    in subclass (LinePlotProperties)
    c:\python\reportlab\graphics\widgetbase.py:1 No module doc string

    here widgetbase is imported by lineplot, but the above errors
    are certainly for linplot.py itself.
    If you send me the code (preferabbly a small test case), I'll take a look
    and try to fix.
    I'm also getting a warning about not calling the base class even when I have got
    an apply(BASE.__init__,.....) I suppose this is more difficult than the straight call.
    Yes, apply() isn't handled, but I added it to the TODO list,
    I think it can be done pretty easily for some better checking.

    Neal
  • Robin Becker at Apr 13, 2001 at 9:50 am
    In article <3AD5C5B1.98ACEFB3 at metaslash.com>, Neal Norwitz
    <neal at metaslash.com> writes
    Robin Becker wrote: ...
    If you send me the code (preferabbly a small test case), I'll take a look
    and try to fix.
    OK I have the following dummy things

    #b.py
    ''
    class B:
    'base class'
    member = 0
    def __init__(self):
    self.x=1

    #a.py
    ''
    from b import B

    class A(B):
    'derived class'
    member = 1

    checker on a.py produces
    C:\Python\pyChecker>python checker.py a.py
    Processing a...

    Warnings...

    b.py:0 No __init__() in subclass (A)

    C:\Python\pyChecker>
    --
    Robin Becker
  • Neal Norwitz at Apr 13, 2001 at 7:25 pm

    Robin Becker wrote:
    class B:
    def __init__(self):
    self.x=1
    class A(B):
    member = 1

    C:\Python\pyChecker>python checker.py a.py

    b.py:0 No __init__() in subclass (A)
    Yes, this was by design. Although the error should be in a.py, not b.py.
    That's been fixed in CVS.

    In addition, I have made this warning configurable. The code is fine,
    it is completely legal to inherit __init__ and not override. The idea
    was that it it is often a mistake to not override.

    But this is not always a good assumption....so....

    -I, --initsubclass Subclass.__init__() not defined [on]

    That's a new command line option in CVS version.

    There are many cases where you want to write completely legal code,
    but checker can't tell if it is a bug (thinko mistake) or what was intended.
    Ideally, there would be finer grain control on the options.

    So one could specify for a particular class/method, set option X to some value.
    In 2.1, this could be done with function attributes. But I don't know how to
    deal with these cases for modules/classes/functions generically.

    One option would be to review the actual doc strings and look for hints
    (similar to lint /*ARGSUSED*/). Perhaps "CHECKER.initsubclass = 1" ?

    Any ideas or comments?

    Neal
  • Alex Martelli at Apr 13, 2001 at 10:12 pm
    "Neal Norwitz" <neal at metaslash.com> wrote in message
    news:3AD752A0.ECF538A4 at metaslash.com...
    [snip]
    There are many cases where you want to write completely legal code,
    but checker can't tell if it is a bug (thinko mistake) or what was intended.
    Ideally, there would be finer grain control on the options. [snip]
    One option would be to review the actual doc strings and look for hints
    (similar to lint /*ARGSUSED*/). Perhaps "CHECKER.initsubclass = 1" ?

    Any ideas or comments?
    Exactly: I'd put the hints in comments (rather than in docstrings)...:-).


    Alex
  • Neal Norwitz at Apr 9, 2001 at 2:18 am

    Robin Becker wrote:
    In article <mailman.986668153.19972.python-list at python.org>, Neal
    Norwitz <neal at metaslash.com> writes
    PyChecker is a python source code checking tool to help you find common bugs.
    It is meant to find problems that area
    typically caught by a compiler. Because of the dynamic nature of python, some
    warnings may be incorrect; however, ....
    orge.net/projects/pychecker/

    Enjoy! Feedback is greatly appreciated.
    Well I just checked SF and see no files in CVS and no released files and
    no downloads. Where should I be looking?

    Robin Becker
    I didn't create a release on SF at the time.
    They should have been available through CVS at http://sourceforge.net/cvs/?group_id$686
    or on web site http://pychecker.sourceforge.net

    I created the release on SF too. So hopefully there won't be
    any more problems finding it.

    I also upgraded (downgraded?) pychecker to run on Python 1.5.2
    as well as Python 2.0.

    Neal
  • Jeff Collins at Apr 9, 2001 at 9:14 pm
    I've needed something like this for some time! Thanks!

    A couple of comments:
    1. I was unable to get it to work with packages, so I made some
    minor modifications to fix that.
    2. I eliminated some leading spaces in the warnings output. Now,
    the output from pychecker.py can be parsed in *grep*-like
    output window in emacs for quick access to the offending lines.
    Perhaps a command-line switch for inclusion into emacs would be
    a better solution.

    If you are interested in these patches, let me know and I'll send them
    along.


    --
    Jeffery D. Collins, Ph.D.
    Sr. Software Developer
    Endeavors Technology, Inc.
    http://www.endeavors.com

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedApr 7, '01 at 6:28p
activeApr 13, '01 at 10:12p
posts17
users8
websitepython.org

People

Translate

site design / logo © 2022 Grokbase