Cause 1 of 5
The block body is missing entirely.
Indent at least one statement under the header line. If the body is genuinely meant to be empty for now, write pass — it is a real statement that does nothing and exists precisely for this.
Python · 5 common causes
Updated
A statement that opens a block — if, for, while, def, class, try — has nothing indented underneath it.
File "/app/main.py", line 4
print("done")
^
IndentationError: expected an indented block after 'if' statement on line 3Paths, line numbers and stack frames differ on every machine, and the wording is tightened between versions. The part that identifies the problem is IndentationError: expected an indented block.
Cause 1 of 5
Indent at least one statement under the header line. If the body is genuinely meant to be empty for now, write pass — it is a real statement that does nothing and exists precisely for this.
Cause 2 of 5
Everything belonging to the block must be indented further than the line ending in a colon. Add one level (four spaces) to every line of the body, not just the first.
Cause 3 of 5
Comments are not statements, so a block containing nothing but # TODO is still empty. Put pass under the comment.
Cause 4 of 5
Convert the file to spaces and reindent. A body indented with a tab, under a header indented with spaces, can render aligned and still fail to parse.
Cause 5 of 5
Check the header itself: deleting a line can leave if condition: immediately followed by a dedented else: or the end of the file. Python 3.10 and newer name the offending statement and its line number in the message, which points straight at it.
Write pass the moment you type a header you are not ready to fill in, and let a formatter and linter run on save so an empty block is caught as you write it.
if x: return 1 is valid. It is discouraged by PEP 8 and cannot hold multiple statements or nested blocks, so use it sparingly if at all.pass is the conventional placeholder in ordinary code; the Ellipsis literal ... is idiomatic in type stubs and protocol definitions. Neither does anything at runtime.Reproducing the failure in a scratch file is usually faster than editing the real one. AltF Code is a free in-browser editor with real syntax highlighting for HTML, CSS, JavaScript, TypeScript, Python, SQL and JSON, and it runs HTML, CSS and JavaScript live in a preview panel. No install and no sign-up.
Open the editor