invalid-length-return-type (PLE0303)
Added in 0.6.0 · Related issues · View source
Derived from the Pylint linter.
What it does
Checks for __len__ implementations that return values that are not non-negative
integers.
Why is this bad?
The __len__ method should return a non-negative integer. Returning a different
value may cause unexpected behavior.
Note: bool is a subclass of int, so it's technically valid for __len__ to
return True or False. However, for consistency with other rules, Ruff will
still emit a diagnostic when __len__ returns a bool.
Example
Use instead: