Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 302 lines (239 sloc) 9.057 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <title>PyChecker: a python source code checking tool</title>
</head>

<body bgcolor="#505050">

<p>&nbsp;</p>

<center>
<table width="95%" bgcolor="#f0f0f0">

<tr><td align="center">

<table width="95%" bgcolor="#f0f0f0">

<tr><td>

<p>&nbsp;</p>

<p>
PyChecker is a tool for finding bugs in
<a href="http://www.python.org">python</a> source code.
It finds problems that are typically caught by a compiler
for less dynamic languages, like C and C++. It is similar to lint.
Because of the dynamic nature of python, some warnings
may be incorrect; however, spurious warnings should be fairly infrequent.

<p>
PyChecker works in a combination of ways. First, it imports each
module. If there is an import error, the module cannot be processed.
The import provides some basic information about the module. The code
for each function, class, and method is checked for possible problems.

<p>
Types of problems that can be found include:

<p>
<ul>
  <li> No global found (e.g., using a module without importing it)
  <li> Passing the wrong number of parameters to functions/methods/constructors
  <li> Passing the wrong number of parameters to builtin functions & methods
  <li> Using format strings that don't match arguments
  <li> Using class methods and attributes that don't exist
  <li> Changing signature when overriding a method
  <li> Redefining a function/class/method in the same scope
  <li> Using a variable before setting it
  <li> self is not the first parameter defined for a method
  <li> Unused globals and locals (module or variable)
  <li> Unused function/method arguments (can ignore self)
  <li> No doc strings in modules, classes, functions, and methods
</ul>

<p>
<a href='http://www.unixreview.com/documents/s=2426/uni1018986621203/0204h.htm'>
Here's an article</a> about PyChecker
in <a href='http://www.unixreview.com'>Unix Review</a>
by Cameron Laird and Kathryn Soraiz.

<h2>Using PyChecker</h2>

<p>
To use PyChecker, pass options and the python source files (or packages)
you want to check on the command line:

<p>
<pre>
pychecker [options] file1.py file2.py ...
</pre>

<p>
Some of the most commonly used options are:
<table width="90%">
<tr><td align="center">
<table cellspacing="5">
  <tr><th>Options</th><th>Description</th><th>Default value</th></tr>

  <tr>
    <td>--only</td>
    <td>only warn about files passed on the command line</td>
    <td align="center">no</td>
  </tr>

  <tr>
    <td>-#, --limit</td>
    <td>the maximum number of warnings to be displayed</td>
    <td align="center">10</td>
  </tr>

  <tr>
    <td>--no-shadowbuiltin</td>
    <td>check if a variable shadows a builtin</td>
    <td align="center">off</td>
  </tr>

  <tr>
    <td>-q, --stdlib</td>
    <td>ignore warnings from files under standard library</td>
    <td align="center">off</td>
  </tr>

  <tr>
    <td>-T, --argsused</td>
    <td>unused method/function arguments</td>
    <td align="center">on</td>
  </tr>

</table>
</td></tr>
</table>

<p>
Note: On Windows, use pychecker.bat. You may also need to add
python/scripts to your PATH.<br>

<p>
pychecker and pychecker.bat will only exist if pychecker has been
installed. To install, do: python setup.py install

<p>
Note: If you haven't installed pychecker, it can be run by doing:
python pychecker/checker.py

<p>
An alternate way to use PyChecker is to import it in your code.
See <a href='#import'>Importing PyChecker</a> below for more details.

<p>
If there are import dependencies in your source files, you should
import those files first on the command line in order to get as many
files checked as possible.

<p>
PyChecker works with Python 2.0 through 2.3.
Some features don't work on earlier versions of Python.
I only regularly test with versions 2.2 and 2.3.

<p>
You can use the test files as examples:

<p>
<pre>
pychecker test_input/*.py
</pre>

<p>
If you want to change the default behaviour, you can pass command line options
or define a .pycheckrc file. For an example, look at
<a href="http://pychecker.cvs.sourceforge.net/pychecker/pychecker/pycheckrc?pathrev=current&view=markup">pycheckrc</a>.

<p>
<pre>
pychecker -h
</pre>

will show the available options.

<p>
There is a simple GUI which is not maintained much. It is good
for showing all the options and also allows you to run pychecker.
To run options, you will need to start it manually:

<p>
<pre>
python pychecker/options.py
</pre>

<p>
If you want to suppress warnings on a module/function/class/method,
you can define a suppressions dictionary in .pycheckrc.
Examples of keys are: 'module', 'module.function',
'module.class', 'module.class.method', etc.

<p>
You can also define suppressions in your code by doing:

<p>
<pre>
        __pychecker__ = 'no-namedargs maxreturns=0 unusednames=foo,bar'
</pre>

<p>
The format for __pychecker__ values and values in the suppressions dictionary
are the same. Dashes (--) are optional when preceding long option names.

<a name='import'><h2>Importing PyChecker</h2></a>
<p>
You can import PyChecker in your code's main module, by doing:

<p><pre>
        import pychecker.checker
</pre>

<p>
This will allow each module imported after PyChecker to be checked
(other than the main module). NOTE: Modules imported before PyChecker
will not be checked. Warnings will be displayed on stdout
(ie, PyChecker uses print).

<p>
Since you can't pass command line parameters, you can do:

<p><pre>
        os.environ['PYCHECKER'] = 'command line options here'
</pre>

<p>
This is equivalent of setting PYCHECKER in the shell environment:

<p><pre>
        PYCHECKER='no-namedargs maxreturns=0' /path/to/your/program
</pre>

<p>
If you want to disable the warnings (and processing done by PyChecker),
prior to importing PyChecker, do:

<p><pre>
        os.environ['PYCHECKER_DISABLED'] = 1
</pre>

<p>
This is equivalent of setting PYCHECKER_DISABLED in the shell environment:

<p><pre>
        PYCHECKER_DISABLED=1 /path/to/your/program
</pre>

<h2>Internal Errors</h2>

<p>
If you find a bug in PyChecker, meaning you see something like:

<pre>
pychecker myfile.py

myfile.py:13 INTERNAL ERROR -- STOPPED PROCESSING FUNCTION --
        Traceback (most recent call last):
          File "./pychecker/warn.py", line 364, in _checkFunction
            stack, oparg, lastLineNum)
          File "./pychecker/warn.py", line 195, in _handleFunctionCall
            kwArgs.append(stack[i].data)
        IndexError: list index out of range
</pre>

Please <a href='https://sourceforge.net/tracker/?atid=382217&group_id=24686&func=browse'>post a bug in the SourceForge Tracker</a>
or send mail indicating the version of PyChecker,
<b>your source file</b> which broke PyChecker
(myfile.py in the example above), and the traceback.
It is very helpful to provide a simple test case to demonstrate the problem.
It helps to have the entire file and all the dependencies if you cannot
produce a simple test case. But if you can't provide a test case nor
the file(s), I may be able to figure out the problem with just the line
which broke PyChecker (myfile.py:13 in the example above).

<p>
Here are some quick links for the <a href="http://pychecker.cvs.sourceforge.net/pychecker/pychecker/VERSION?pathrev=current&view=markup">latest released version</a>
of PyChecker:
<ul>
  <li><a href="http://sourceforge.net/project/showfiles.php?group_id=24686">Download Latest Release</a>
  <li><a href="http://pychecker.cvs.sourceforge.net/pychecker/pychecker/NEWS?pathrev=current&view=markup">NEWS</a>
  <li><a href="http://pychecker.cvs.sourceforge.net/pychecker/pychecker/ChangeLog?pathrev=current&view=markup">ChangeLog</a>
  <li><a href="http://pychecker.cvs.sourceforge.net/pychecker/pychecker/TODO?pathrev=current&view=markup">TODO list</a>
  <li><a href="http://pychecker.cvs.sourceforge.net/pychecker/pychecker/KNOWN_BUGS?pathrev=current&view=markup">Known Problems</a>
  <li><a href="COPYRIGHT">COPYRIGHT (BSD)</a>
</ul>

<p>
The development version is usually quite stable.
Here are links to track the development status:
<ul>
  <li><a href="http://pychecker.cvs.sourceforge.net/pychecker/pychecker/NEWS?pathrev=HEAD&view=markup">NEWS</a>
  <li><a href="http://pychecker.cvs.sourceforge.net/pychecker/pychecker/ChangeLog?pathrev=HEAD&view=markup">ChangeLog</a>
  <li><a href="http://pychecker.cvs.sourceforge.net/pychecker/pychecker/TODO?pathrev=HEAD&view=markup">TODO list</a>
  <li><a href="http://pychecker.cvs.sourceforge.net/pychecker/pychecker/KNOWN_BUGS?pathrev=HEAD&view=markup">Known Problems</a>
</ul>

<p>
The project page for PyChecker can be found on
<a href="http://sf.net/projects/pychecker">SourceForge</a>.

<p>
Good Luck! As always, feedback is greatly appreciated.

<p>
Neal
<address>
<a href="mailto:pychecker-list@lists.sourceforge.net">pychecker-list@lists.sourceforge.net</a>
</address>

<p>&nbsp;</p>
</td></tr>

</table>
</td></tr>
</table>
</center>

</body>
</html>
Something went wrong with that request. Please try again.