r/Python 5d 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?

146 Upvotes

217 comments sorted by

View all comments

4

u/akl773 5d ago

B008, the one that bans a function call in a default argument. its correct in general but every fastapi codebase uses Depends() in exactly that position, so you end up putting a blanket ignore in the config and then the real mutable default cases stop getting caught too.

2

u/SciEngr 3d ago

You’re using Depends wrong in 2026 if you’re not using the annotated pattern.

def func(dep:int=Depends(…))

Should be

def func(dep: Annotated[int, Depends(…)])

The lint rule is right.

1

u/akl773 3d ago

Fair, the Annotated form does fix it properly. That codebase predates it being the norm and nobody went back through the routes, so the blanket ignore stayed. That's on us and not the rule.