---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
PLC1802 [*] `len('TEST')` used as condition without comparison
 --> len_as_condition.py:1:4
  |
1 | if len('TEST'):  # [PLC1802]
  |    ^^^^^^^^^^^
2 |     pass
  |
help: Remove `len`
  |
  - if len('TEST'):  # [PLC1802]
1 + if 'TEST':  # [PLC1802]
2 |     pass
  |

PLC1802 [*] `len('TEST')` used as condition without comparison
 --> len_as_condition.py:4:8
  |
2 |     pass
3 |
4 | if not len('TEST'):  # [PLC1802]
  |        ^^^^^^^^^^^
5 |     pass
  |
help: Remove `len`
  |
3 |
  - if not len('TEST'):  # [PLC1802]
4 + if not 'TEST':  # [PLC1802]
5 |     pass
  |

PLC1802 [*] `len(['T', 'E', 'S', 'T'])` used as condition without comparison
 --> len_as_condition.py:8:10
  |
7 | z = []
8 | if z and len(['T', 'E', 'S', 'T']):  # [PLC1802]
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^
9 |     pass
  |
help: Remove `len`
  |
7 | z = []
  - if z and len(['T', 'E', 'S', 'T']):  # [PLC1802]
8 + if z and ['T', 'E', 'S', 'T']:  # [PLC1802]
9 |     pass
  |

PLC1802 [*] `len('TEST')` used as condition without comparison
  --> len_as_condition.py:11:12
   |
 9 |     pass
10 |
11 | if True or len('TEST'):  # [PLC1802]
   |            ^^^^^^^^^^^
12 |     pass
   |
help: Remove `len`
   |
10 |
   - if True or len('TEST'):  # [PLC1802]
11 + if True or 'TEST':  # [PLC1802]
12 |     pass
   |

PLC1802 [*] `len('TEST')` used as condition without comparison
  --> len_as_condition.py:53:6
   |
51 | if z:
52 |     pass
53 | elif len('TEST'):  # [PLC1802]
   |      ^^^^^^^^^^^
54 |     pass
   |
help: Remove `len`
   |
52 |     pass
   - elif len('TEST'):  # [PLC1802]
53 + elif 'TEST':  # [PLC1802]
54 |     pass
   |

PLC1802 [*] `len('TEST')` used as condition without comparison
  --> len_as_condition.py:58:10
   |
56 | if z:
57 |     pass
58 | elif not len('TEST'):  # [PLC1802]
   |          ^^^^^^^^^^^
59 |     pass
   |
help: Remove `len`
   |
57 |     pass
   - elif not len('TEST'):  # [PLC1802]
58 + elif not 'TEST':  # [PLC1802]
59 |     pass
   |

PLC1802 [*] `len('TEST')` used as condition without comparison
  --> len_as_condition.py:61:7
   |
59 |     pass
60 |
61 | while len('TEST'):  # [PLC1802]
   |       ^^^^^^^^^^^
62 |     pass
   |
help: Remove `len`
   |
60 |
   - while len('TEST'):  # [PLC1802]
61 + while 'TEST':  # [PLC1802]
62 |     pass
   |

PLC1802 [*] `len('TEST')` used as condition without comparison
  --> len_as_condition.py:64:11
   |
62 |     pass
63 |
64 | while not len('TEST'):  # [PLC1802]
   |           ^^^^^^^^^^^
65 |     pass
   |
help: Remove `len`
   |
63 |
   - while not len('TEST'):  # [PLC1802]
64 + while not 'TEST':  # [PLC1802]
65 |     pass
   |

PLC1802 [*] `len('TEST')` used as condition without comparison
  --> len_as_condition.py:67:13
   |
65 |     pass
66 |
67 | while z and len('TEST'):  # [PLC1802]
   |             ^^^^^^^^^^^
68 |     pass
   |
help: Remove `len`
   |
66 |
   - while z and len('TEST'):  # [PLC1802]
67 + while z and 'TEST':  # [PLC1802]
68 |     pass
   |

PLC1802 [*] `len('TEST')` used as condition without comparison
  --> len_as_condition.py:70:11
   |
68 |     pass
69 |
70 | while not len('TEST') and z:  # [PLC1802]
   |           ^^^^^^^^^^^
71 |     pass
   |
help: Remove `len`
   |
69 |
   - while not len('TEST') and z:  # [PLC1802]
70 + while not 'TEST' and z:  # [PLC1802]
71 |     pass
   |

PLC1802 [*] `len(args)` used as condition without comparison
  --> len_as_condition.py:93:12
   |
92 | def github_issue_1331_v2(*args):
93 |     assert len(args), args  # [PLC1802]
   |            ^^^^^^^^^
94 |
95 | def github_issue_1331_v3(*args):
   |
help: Remove `len`
   |
92 | def github_issue_1331_v2(*args):
   -     assert len(args), args  # [PLC1802]
93 +     assert args, args  # [PLC1802]
94 |
   |

PLC1802 [*] `len(args)` used as condition without comparison
  --> len_as_condition.py:96:12
   |
95 | def github_issue_1331_v3(*args):
96 |     assert len(args) or z, args  # [PLC1802]
   |            ^^^^^^^^^
97 |
98 | def github_issue_1331_v4(*args):
   |
help: Remove `len`
   |
95 | def github_issue_1331_v3(*args):
   -     assert len(args) or z, args  # [PLC1802]
96 +     assert args or z, args  # [PLC1802]
97 |
   |

PLC1802 [*] `len(args)` used as condition without comparison
   --> len_as_condition.py:99:18
    |
 98 | def github_issue_1331_v4(*args):
 99 |     assert z and len(args), args  # [PLC1802]
    |                  ^^^^^^^^^
100 |
101 | def github_issue_1331_v5(**args):
    |
help: Remove `len`
    |
98  | def github_issue_1331_v4(*args):
    -     assert z and len(args), args  # [PLC1802]
99  +     assert z and args, args  # [PLC1802]
100 |
    |

PLC1802 [*] `len(args)` used as condition without comparison
   --> len_as_condition.py:102:18
    |
101 | def github_issue_1331_v5(**args):
102 |     assert z and len(args), args  # [PLC1802]
    |                  ^^^^^^^^^
103 |
104 | b = bool(len(z)) # [PLC1802]
    |
help: Remove `len`
    |
101 | def github_issue_1331_v5(**args):
    -     assert z and len(args), args  # [PLC1802]
102 +     assert z and args, args  # [PLC1802]
103 |
    |

PLC1802 [*] `len(z)` used as condition without comparison
   --> len_as_condition.py:104:10
    |
102 |     assert z and len(args), args  # [PLC1802]
103 |
104 | b = bool(len(z)) # [PLC1802]
    |          ^^^^^^
105 | c = bool(len('TEST') or 42) # [PLC1802]
    |
help: Remove `len`
    |
103 |
    - b = bool(len(z)) # [PLC1802]
104 + b = bool(z) # [PLC1802]
105 | c = bool(len('TEST') or 42) # [PLC1802]
    |

PLC1802 [*] `len('TEST')` used as condition without comparison
   --> len_as_condition.py:105:10
    |
104 | b = bool(len(z)) # [PLC1802]
105 | c = bool(len('TEST') or 42) # [PLC1802]
    |          ^^^^^^^^^^^
106 |
107 | def github_issue_1879():
    |
help: Remove `len`
    |
104 | b = bool(len(z)) # [PLC1802]
    - c = bool(len('TEST') or 42) # [PLC1802]
105 + c = bool('TEST' or 42) # [PLC1802]
106 |
    |

PLC1802 [*] `len(range(0))` used as condition without comparison
   --> len_as_condition.py:126:12
    |
124 |     assert len(ClassWithoutBool())  # unintuitive?, in pylint: [PLC1802]
125 |     assert len(ChildClassWithoutBool())  # unintuitive?, in pylint: [PLC1802]
126 |     assert len(range(0))  # [PLC1802]
    |            ^^^^^^^^^^^^^
127 |     assert len([t + 1 for t in []])  # [PLC1802]
128 |     # assert len(u + 1 for u in []) generator has no len
    |
help: Remove `len`
    |
125 |     assert len(ChildClassWithoutBool())  # unintuitive?, in pylint: [PLC1802]
    -     assert len(range(0))  # [PLC1802]
126 +     assert range(0)  # [PLC1802]
127 |     assert len([t + 1 for t in []])  # [PLC1802]
    |

PLC1802 [*] `len([t + 1 for t in []])` used as condition without comparison
   --> len_as_condition.py:127:12
    |
125 |     assert len(ChildClassWithoutBool())  # unintuitive?, in pylint: [PLC1802]
126 |     assert len(range(0))  # [PLC1802]
127 |     assert len([t + 1 for t in []])  # [PLC1802]
    |            ^^^^^^^^^^^^^^^^^^^^^^^^
128 |     # assert len(u + 1 for u in []) generator has no len
129 |     assert len({"1":(v + 1) for v in {}})  # [PLC1802]
    |
help: Remove `len`
    |
126 |     assert len(range(0))  # [PLC1802]
    -     assert len([t + 1 for t in []])  # [PLC1802]
127 +     assert [t + 1 for t in []]  # [PLC1802]
128 |     # assert len(u + 1 for u in []) generator has no len
    |

PLC1802 [*] `len({"1":(v + 1) for v in {}})` used as condition without comparison
   --> len_as_condition.py:129:12
    |
127 |     assert len([t + 1 for t in []])  # [PLC1802]
128 |     # assert len(u + 1 for u in []) generator has no len
129 |     assert len({"1":(v + 1) for v in {}})  # [PLC1802]
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
130 |     assert len(set((w + 1) for w in set()))  # [PLC1802]
    |
help: Remove `len`
    |
128 |     # assert len(u + 1 for u in []) generator has no len
    -     assert len({"1":(v + 1) for v in {}})  # [PLC1802]
129 +     assert {"1":(v + 1) for v in {}}  # [PLC1802]
130 |     assert len(set((w + 1) for w in set()))  # [PLC1802]
    |

PLC1802 [*] `len(set((w + 1) for w in set()))` used as condition without comparison
   --> len_as_condition.py:130:12
    |
128 |     # assert len(u + 1 for u in []) generator has no len
129 |     assert len({"1":(v + 1) for v in {}})  # [PLC1802]
130 |     assert len(set((w + 1) for w in set()))  # [PLC1802]
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
help: Remove `len`
    |
129 |     assert len({"1":(v + 1) for v in {}})  # [PLC1802]
    -     assert len(set((w + 1) for w in set()))  # [PLC1802]
130 +     assert set((w + 1) for w in set())  # [PLC1802]
131 |
    |

PLC1802 [*] `len(x)` used as condition without comparison
   --> len_as_condition.py:193:8
    |
191 |     if cond:
192 |         x = [4,5,6]
193 |     if len(x): # this should be addressed
    |        ^^^^^^
194 |         print(x)
    |
help: Remove `len`
    |
192 |         x = [4,5,6]
    -     if len(x): # this should be addressed
193 +     if x: # this should be addressed
194 |         print(x)
    |

PLC1802 [*] `len(x)` used as condition without comparison
   --> len_as_condition.py:200:8
    |
198 |     if cond:
199 |         x = [4,5,6]
200 |     if len(x): # this should be addressed
    |        ^^^^^^
201 |         print(x)
202 |     del x
    |
help: Remove `len`
    |
199 |         x = [4,5,6]
    -     if len(x): # this should be addressed
200 +     if x: # this should be addressed
201 |         print(x)
    |

PLC1802 [*] `len(x)` used as condition without comparison
   --> len_as_condition.py:214:8
    |
212 |     def inner(x:int):
213 |         return x+1
214 |     if len(x): # [PLC1802]
    |        ^^^^^^
215 |         print(x)
    |
help: Remove `len`
    |
213 |         return x+1
    -     if len(x): # [PLC1802]
214 +     if x: # [PLC1802]
215 |         print(x)
    |

PLC1802 [*] `len(x)` used as condition without comparison
   --> len_as_condition.py:220:8
    |
218 |     x = 123
219 |     x = [1, 2, 3]
220 |     if len(x): # this should be addressed
    |        ^^^^^^
221 |         print(x)
    |
help: Remove `len`
    |
219 |     x = [1, 2, 3]
    -     if len(x): # this should be addressed
220 +     if x: # this should be addressed
221 |         print(x)
    |

PLC1802 [*] `len(x)` used as condition without comparison
   --> len_as_condition.py:233:8
    |
231 |     if False:
232 |         x = [1, 2, 3]
233 |     if len(x): # [PLC1802] should be fine
    |        ^^^^^^
234 |         print(x)
    |
help: Remove `len`
    |
232 |         x = [1, 2, 3]
    -     if len(x): # [PLC1802] should be fine
233 +     if x: # [PLC1802] should be fine
234 |         print(x)
    |

PLC1802 [*] `len(ascii(1))` used as condition without comparison
   --> len_as_condition.py:237:6
    |
236 | # regression tests for https://github.com/astral-sh/ruff/issues/14690
237 | bool(len(ascii(1)))
    |      ^^^^^^^^^^^^^
238 | bool(len(sorted("")))
    |
help: Remove `len`
    |
236 | # regression tests for https://github.com/astral-sh/ruff/issues/14690
    - bool(len(ascii(1)))
237 + bool(ascii(1))
238 | bool(len(sorted("")))
    |

PLC1802 [*] `len(sorted(""))` used as condition without comparison
   --> len_as_condition.py:238:6
    |
236 | # regression tests for https://github.com/astral-sh/ruff/issues/14690
237 | bool(len(ascii(1)))
238 | bool(len(sorted("")))
    |      ^^^^^^^^^^^^^^^
239 |
240 | # regression tests for https://github.com/astral-sh/ruff/issues/18811
    |
help: Remove `len`
    |
237 | bool(len(ascii(1)))
    - bool(len(sorted("")))
238 + bool(sorted(""))
239 |
    |

PLC1802 [*] `len(fruits)` used as condition without comparison
   --> len_as_condition.py:242:3
    |
240 | # regression tests for https://github.com/astral-sh/ruff/issues/18811
241 | fruits = []
242 | if(len)(fruits):
    |   ^^^^^^^^^^^^^
243 |     ...
    |
help: Remove `len`
    |
241 | fruits = []
    - if(len)(fruits):
242 + if fruits:
243 |     ...
    |

PLC1802 [*] `len(fruits)` used as condition without comparison
   --> len_as_condition.py:247:4
    |
245 |   # regression tests for https://github.com/astral-sh/ruff/issues/18812
246 |   fruits = []
247 |   if len(
    |  ____^
248 | |     fruits  # comment
249 | | ):
    | |_^
250 |       ...
    |
help: Remove `len`
    |
246 | fruits = []
    - if len(
    -     fruits  # comment
    - ):
247 + if fruits:
248 |     ...
    |
note: This is an unsafe fix and may change runtime behavior
