Unnecessary pass Statement
ID |
python.unnecessary_pass |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Python |
Tags |
code-style, dead-code |
Description
Reports pass statements that appear in a block that already contains another statement. pass exists only to satisfy Python’s grammar requirement that a block contain at least one statement; once a real statement is present, the pass adds nothing and just clutters the body.
def foo():
do_work()
pass # FLAW
def empty():
pass # OK — required by the grammar
class Marker:
pass # OK — required by the grammar
Rationale
Stray pass lines accumulate as scaffolding that never got cleaned up. Each one slows reviewers and obscures the real shape of the function.
Remediation
Delete the pass. It only belongs in genuinely empty blocks (placeholder classes, abstract methods, empty except branches that re-raise elsewhere).