Rule to force var = <default> if value is None else value
instead of var = value or <default>
for value: int | None = None
#16107
Labels
needs-decision
Awaiting a decision from a maintainer
rule
Implementing or modifying a lint rule
type-inference
Requires more advanced type inference.
Description
I often see the pattern of a function taking a parameter such as
value: int | None = None
and then having an internal default by doingvar = value or 1
. This is problematic because 0 and None are both falsy:I guess one might do this intentionally, but unless you are explicit the meaning is unclear. I would rather see one of:
Arguably in these simple cases just making the parameter
value: int = 1
would be better, but I believe there are use cases for this pattern or it is at least a pattern that existsThe text was updated successfully, but these errors were encountered: