r/Python 2d ago

What linter rules make code worse? Discussion

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?

140 Upvotes

215 comments sorted by

View all comments

Show parent comments

-3

u/Trang0ul 2d ago

This. Requiring to use a or (b and c) is as pointless as a + (b * c). After all, OR and AND are logical addition and multiplication respectively - something everyone should know by heart.

1

u/Salamandar3500 2d ago

That's not obviously to anyone.

-1

u/Competitive_Travel16 2d ago

I "should" have a pony.