Skip to content

PLC1802 has false negatives for ascii and sorted #14690

@dscorbett

Description

@dscorbett

len-test (PLC1802) in Ruff 0.8.1 does not recognize the builtins ascii and sorted as returning sequences, leading to false negatives.

$ cat plc1802.py
bool(len(ascii(1)))
bool(len(sorted("")))

$ ruff check --preview --isolated --select PLC1802 plc1802.py --output-format concise
All checks passed!

Compare similar builtins with true positives.

$ cat plc1802.py 
bool(len(repr(1)))
bool(len(list("")))

$ ruff check --preview --isolated --select PLC1802 plc1802.py --output-format concise
plc1802.py:1:6: PLC1802 [*] `len(repr(1))` used as condition without comparison
plc1802.py:2:6: PLC1802 [*] `len(list(""))` used as condition without comparison
Found 2 errors.
[*] 2 fixable with the `--fix` option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions