Typing and Source Modules

tabnanny

Detects ambiguous indentation in Python source, particularly where tabs and spaces can be interpreted differently. check reports diagnostics for files or directories; process_tokens raises NannyNag when ambiguity is detected. It is not a complete parser or style checker. Prefer consistent spaces for indentation.

Formal Syntax & Structure

python syntaxpython
import tabnanny

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import tabnanny, tokenizefrom io import StringIOsource = "if True:\n    value = 2\n"tabnanny.process_tokens(tokenize.generate_tokens(StringIO(source).readline))print("No ambiguous indentation detected")
Python Reference