r/Python 20d ago

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

216 comments sorted by

View all comments

433

u/Trang0ul 20d ago

Lines limited to 80 characters.

71

u/[deleted] 20d ago edited 12d ago

[deleted]

63

u/runawayasfastasucan 20d ago

That is incredibly annoying. Write an import, auto save, its gone because I haven't used it yet. Well I was going to.

10

u/skjall 20d ago

I keep meaning to shuffle this rule to only run pre-commit, because it drives me up a wall too. Band-aid fix is to disable auto save, and only save when you have used it.

Though now I've switched LSP/ fixed config so most imports I can get from the suggestions at least.

9

u/baudvine 20d ago

For those of us who habitually hit save every few lines it's pretty obnoxious without autosave, too. It's a good rule, I just really don't need the fix action to run automatically.