mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
[pylint
] Fix false negatives for ascii
and sorted
in len-as-condition
(PLC1802) (#14692)
This commit is contained in:
parent
be07424e80
commit
56ae73a925
3 changed files with 41 additions and 0 deletions
|
@ -232,3 +232,7 @@ def j():
|
|||
x = [1, 2, 3]
|
||||
if len(x): # [PLC1802] should be fine
|
||||
print(x)
|
||||
|
||||
# regression tests for https://github.com/astral-sh/ruff/issues/14690
|
||||
bool(len(ascii(1)))
|
||||
bool(len(sorted("")))
|
||||
|
|
|
@ -186,6 +186,8 @@ fn is_sequence(expr: &Expr, semantic: &SemanticModel) -> bool {
|
|||
| "hex"
|
||||
| "memoryview"
|
||||
| "oct"
|
||||
| "ascii"
|
||||
| "sorted"
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -434,3 +434,38 @@ len_as_condition.py:233:8: PLC1802 [*] `len(x)` used as condition without compar
|
|||
233 |- if len(x): # [PLC1802] should be fine
|
||||
233 |+ if x: # [PLC1802] should be fine
|
||||
234 234 | print(x)
|
||||
235 235 |
|
||||
236 236 | # regression tests for https://github.com/astral-sh/ruff/issues/14690
|
||||
|
||||
len_as_condition.py:237:6: PLC1802 [*] `len(ascii(1))` used as condition without comparison
|
||||
|
|
||||
236 | # regression tests for https://github.com/astral-sh/ruff/issues/14690
|
||||
237 | bool(len(ascii(1)))
|
||||
| ^^^^^^^^^^^^^ PLC1802
|
||||
238 | bool(len(sorted("")))
|
||||
|
|
||||
= help: Remove `len`
|
||||
|
||||
ℹ Safe fix
|
||||
234 234 | print(x)
|
||||
235 235 |
|
||||
236 236 | # regression tests for https://github.com/astral-sh/ruff/issues/14690
|
||||
237 |-bool(len(ascii(1)))
|
||||
237 |+bool(ascii(1))
|
||||
238 238 | bool(len(sorted("")))
|
||||
|
||||
len_as_condition.py:238:6: PLC1802 [*] `len(sorted(""))` used as condition without comparison
|
||||
|
|
||||
236 | # regression tests for https://github.com/astral-sh/ruff/issues/14690
|
||||
237 | bool(len(ascii(1)))
|
||||
238 | bool(len(sorted("")))
|
||||
| ^^^^^^^^^^^^^^^ PLC1802
|
||||
|
|
||||
= help: Remove `len`
|
||||
|
||||
ℹ Safe fix
|
||||
235 235 |
|
||||
236 236 | # regression tests for https://github.com/astral-sh/ruff/issues/14690
|
||||
237 237 | bool(len(ascii(1)))
|
||||
238 |-bool(len(sorted("")))
|
||||
238 |+bool(sorted(""))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue