On this page
  1. tabnanny
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Checking a Directory Tree from the CLI
  7. Gotchas & Boundaries
  8. Common Functions
  9. Classes & Objects

tabnanny

Prev: syslog | Up: stdlib_module | Next: tarfile
Rel: sys, sysconfig, builtins, warnings, dataclasses
Ref: docs.python.org — tabnanny
Tags: #public #python3 #stdlib


Import

import tabnanny

Overview

Ambiguous-indentation checker (check(), process_tokens(), or python3 -m tabnanny <path>) that scans Python source files for mixed tabs and spaces that could mean different things depending on tab-stop width. Run tabnanny as a quick legacy-code sanity check; for modern codebases, a linter like ruff or flake8 catches indentation issues alongside everything else.

Quick Start

from pathlib import Path
import tabnanny
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    clean = Path(tmp) / "ok.py"
    clean.write_text("def f():\n    return 1\n", encoding="utf-8")
    tabnanny.check(str(clean))   # prints nothing when indentation is unambiguous

Implementation Walkthrough

1. Checking a Directory Tree from the CLI

Run python3 -m tabnanny src/ (add -v for verbose output) to scan every .py file recursively and report any file with ambiguous tab/space mixing.

Gotchas & Boundaries

Common Functions

Classes & Objects

Linked from

Related notes