blob: dfe688a2f93e0cbc0ce59eeb83664ea2b96c4cfe [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`tabnanny` --- Detection of ambiguous indentation
2======================================================
3
4.. module:: tabnanny
Georg Brandl7f01a132009-09-16 15:58:14 +00005 :synopsis: Tool for detecting white space related problems in Python
6 source files in a directory tree.
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04007
Georg Brandl116aa622007-08-15 14:28:22 +00008.. moduleauthor:: Tim Peters <tim_one@users.sourceforge.net>
9.. sectionauthor:: Peter Funk <pf@artcom-gmbh.de>
10
Christian Heimes5b5e81c2007-12-31 16:14:33 +000011.. rudimentary documentation based on module comments
Georg Brandl116aa622007-08-15 14:28:22 +000012
Raymond Hettingera1993682011-01-27 01:20:32 +000013**Source code:** :source:`Lib/tabnanny.py`
14
15--------------
16
Georg Brandl116aa622007-08-15 14:28:22 +000017For the time being this module is intended to be called as a script. However it
18is possible to import it into an IDE and use the function :func:`check`
19described below.
20
Georg Brandle720c0a2009-04-27 16:20:50 +000021.. note::
Georg Brandl116aa622007-08-15 14:28:22 +000022
Georg Brandle720c0a2009-04-27 16:20:50 +000023 The API provided by this module is likely to change in future releases; such
Georg Brandl116aa622007-08-15 14:28:22 +000024 changes may not be backward compatible.
25
26
27.. function:: check(file_or_dir)
28
29 If *file_or_dir* is a directory and not a symbolic link, then recursively
30 descend the directory tree named by *file_or_dir*, checking all :file:`.py`
Georg Brandl6911e3c2007-09-04 07:15:32 +000031 files along the way. If *file_or_dir* is an ordinary Python source file, it
32 is checked for whitespace related problems. The diagnostic messages are
33 written to standard output using the :func:`print` function.
Georg Brandl116aa622007-08-15 14:28:22 +000034
35
36.. data:: verbose
37
38 Flag indicating whether to print verbose messages. This is incremented by the
39 ``-v`` option if called as a script.
40
41
42.. data:: filename_only
43
44 Flag indicating whether to print only the filenames of files containing
45 whitespace related problems. This is set to true by the ``-q`` option if called
46 as a script.
47
48
49.. exception:: NannyNag
50
Jelle Zijlstra75b6cf82017-03-21 23:53:57 -070051 Raised by :func:`process_tokens` if detecting an ambiguous indent. Captured and
Georg Brandl116aa622007-08-15 14:28:22 +000052 handled in :func:`check`.
53
54
Jelle Zijlstra75b6cf82017-03-21 23:53:57 -070055.. function:: process_tokens(tokens)
Georg Brandl116aa622007-08-15 14:28:22 +000056
Jelle Zijlstra75b6cf82017-03-21 23:53:57 -070057 This function is used by :func:`check` to process tokens generated by the
58 :mod:`tokenize` module.
Georg Brandl116aa622007-08-15 14:28:22 +000059
Christian Heimes5b5e81c2007-12-31 16:14:33 +000060.. XXX document errprint, format_witnesses, Whitespace, check_equal, indents,
61 reset_globals
Georg Brandl116aa622007-08-15 14:28:22 +000062
63
64.. seealso::
65
66 Module :mod:`tokenize`
67 Lexical scanner for Python source code.