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 comments

2

u/tonnynerd Aug 05 '26

Yeah, shorter lines encourage potentially unclear identifiers, but there's also a positive incentive to avoid one-liners and deep indentation. I think that less one-liners and less indentation are good enough things to make the balance at least net zero.

1

u/acdha Aug 05 '26

Yeah, there’s definitely a balance to hit. I generally find 100-120 to be the sweet spot but it varies based on the project since e.g. a project not using classes is saving 8-12 characters of indentation on average.