Skip to content

Remove Redundant Pass

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Sourcery refactoring id: remove-redundant-pass

Section titled “Sourcery refactoring id: remove-redundant-pass”

Removes unnecessary pass statements

if a:
x()
else:
pass
do_something()
pass
if a:
x()
do_something()

A pass statement is unnecessary if a block has other statements in it, and an else which only contains pass can be safely removed. Making these changes shortens the code, and the reader doesn’t have to consider and deal with the unnecessary pass statements.