Test files › Source code › mixed-indentation.py

Sample Python file (mixed indentation)

Python that mixes tab and space indentation inside one block, which the interpreter rejects.

↓ Download mixed-indentation.py
Filenamemixed-indentation.py
FormatPython
Size146 bytes (146 bytes)
MIME typetext/x-python; charset=utf-8
SHA-256ebf668cedebc40c144d82aad5bc1b02c05697e8428db91faa23f44924b416c54
What this file catchesEditors, formatters and diff views that render tabs and spaces identically, so the file looks perfectly aligned on screen and still fails with TabError at import. Also any tool that strips or normalises whitespace on upload and changes what the code means.

Handle it in code

Each snippet below was run against this exact file with Python 3.14.4 and Node 24.15.0 when this page was built, and the output shown is what it printed.

Python

The standard tabnanny module finds indentation that mixes tabs and spaces ambiguously, the kind that looks right in one editor and raises TabError in Python 3.

import contextlib
import io
import tabnanny

report = io.StringIO()
with contextlib.redirect_stdout(report):
    tabnanny.check("mixed-indentation.py")
print(report.getvalue().strip() or "indentation is consistent")

Run against this file, it prints: mixed-indentation.py 4 '\t\ttotal += row # this line is indented with TABS, the rest with spaces'

Related guides and tools

MIME typesVerify its SHA-256

Download & verify

curl -fsSL -o "mixed-indentation.py" "https://files.hexaqa.com/code/mixed-indentation.py"
curl -fsSL "https://files.hexaqa.com/code/mixed-indentation.py" | sha256sum # expect: ebf668cedebc40c144d82aad5bc1b02c05697e8428db91faa23f44924b416c54

More source code test files

sample.pysample.tsschema.sql

← All Source code files