Mixing tabs and spaces can create blocks that look aligned while the interpreter reads them differently. tabnanny walks Python files and reports ambiguous indentation before execution.
Check a directory
python -m tabnanny src tests
Use the API in small automations
tabnanny.check(path) accepts a file or directory. NannyNag provides a line and context, but the module output is primarily diagnostic. In CI, preserve both the command status and its log.
Fix indentation deliberately
Configure the editor to insert spaces and display invisible characters. Do not replace tabs mechanically inside strings, data, or non-Python files. After the correction, compile and test the code to confirm block structure still matches intent.
Keep learning
Continue with syntax checks with compileall. The official Python documentation, accessed July 22, 2026, explains recursive checks and ambiguity detection.