tabnanny — Indentation validator

Purpose:Scan Python source code looking for suspicious indentation.

Consistent use of indentation is important in a langauge like Python, where white-space is significant. The tabnanny module provides a scanner to report on ambiguous use of indentation.

Running from the Command Line

The simplest way to use tabnanny is to run it from the command line, passing the names of files to check. If you pass directory names, the directories are scanned recursively to find .py files to check.

Running tabnanny across the PyMOTW source code exposed one old module with tabs instead of spaces.

$ python3 -m tabnanny .
./source/queue/ 65 "    \t\tparsed_url = \

Line 65 of had two tabs instead of 8 spaces. This wasn’t apparent in a text editor, which was configured to with tabstops set to 4 spaces, so visually there was no difference.

        for enclosure in entry.get('enclosures', []):
            parsed_url = urlparse(enclosure['url'])
            message('queuing {}'.format(

Correcting line 65 and running tabnanny again showed another error on line 66. One last problem showed up on line 67.

If you want to scan files, but not see the details about the error, use the -q option to suppress all information except the filename.

$ python3 -m tabnanny -q .

To see more information about the files being scanned, use the -v option.

'source/queue/': listing directory
'source/queue/': *** Line 65: trouble in tab
city! ***
offending line: "    \t\tparsed_url = urlparse(enclosure['url'])
indent not greater e.g. at tab sizes 1, 2
'source/queue/': Clean bill of health.
'source/queue/': Clean bill of health.
'source/queue/': Clean bill of health.


Running these examples against the PyMOTW source files won’t report the same errors, since the issues have been fixed.

See also