Skip to content

Remove Assert True

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-assert-true

Section titled “Sourcery refactoring id: remove-assert-true”

Remove assert True statements

print("Checking things")
assert True
assert True, "Always true"
assert len([0, 1, 2]) >= 0, "This is also always true"
print("Done")
print("Checking things")
print("Done")

Assertions are useful to make sure that some conditions hold during the execution of a program. However, when the expression being evaluated is always true, no assertion is necessary, and removing it makes code simpler and easier to understand.