r/Python • • Aug 05 '26

Discussion What linter rules make code worse?

For me, a prime example is S101 which bans the use of the assert statement.

The justification is that assertions disappear when Python is run with -O, so they should not be used for runtime validation or enforcing interface constraints. That warning is correct, but the rule seems to draw the wrong conclusion from it.

Assertions are still very useful for checking internal invariants, i.e. conditions that should already be guaranteed by the program's logic, where failure indicates a bug. Having such assertions is incredibly helpful for debugging.

So, a blanket ban seems more likely to discourage useful checks than to prevent misuse.

Are there any linter rules you broadly consider more harmful rather than helpful?

151 Upvotes

213 comments sorted by

View all comments

Show parent comment

2

u/larsga Aug 05 '26

There should be a rule in the codebase for which exception is used in cases like this, and where it is handled. I agree it can be difficult to reach and enforce consensus on this in larger code bases, but it's a big problem if that doesn't happen.

2

u/xBBTx Aug 05 '26

AssertionError is that rule :) it works well in our large codebases. And yes, run in prod with the optimize flag on, and run the test suite with the flag off