---
source: crates/ruff_linter/src/rules/flake8_pie/mod.rs
---
PIE810.py:2:1: PIE810 [*] Call `startswith` once with a `tuple`
  |
1 | # error
2 | obj.startswith("foo") or obj.startswith("bar")
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE810
3 | # error
4 | obj.endswith("foo") or obj.endswith("bar")
  |
  = help: Merge into a single `startswith` call

ℹ Unsafe fix
1 1 | # error
2   |-obj.startswith("foo") or obj.startswith("bar")
  2 |+obj.startswith(("foo", "bar"))
3 3 | # error
4 4 | obj.endswith("foo") or obj.endswith("bar")
5 5 | # error

PIE810.py:4:1: PIE810 [*] Call `endswith` once with a `tuple`
  |
2 | obj.startswith("foo") or obj.startswith("bar")
3 | # error
4 | obj.endswith("foo") or obj.endswith("bar")
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE810
5 | # error
6 | obj.startswith(foo) or obj.startswith(bar)
  |
  = help: Merge into a single `endswith` call

ℹ Unsafe fix
1 1 | # error
2 2 | obj.startswith("foo") or obj.startswith("bar")
3 3 | # error
4   |-obj.endswith("foo") or obj.endswith("bar")
  4 |+obj.endswith(("foo", "bar"))
5 5 | # error
6 6 | obj.startswith(foo) or obj.startswith(bar)
7 7 | # error

PIE810.py:6:1: PIE810 [*] Call `startswith` once with a `tuple`
  |
4 | obj.endswith("foo") or obj.endswith("bar")
5 | # error
6 | obj.startswith(foo) or obj.startswith(bar)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE810
7 | # error
8 | obj.startswith(foo) or obj.startswith("foo")
  |
  = help: Merge into a single `startswith` call

ℹ Unsafe fix
3 3 | # error
4 4 | obj.endswith("foo") or obj.endswith("bar")
5 5 | # error
6   |-obj.startswith(foo) or obj.startswith(bar)
  6 |+obj.startswith((foo, bar))
7 7 | # error
8 8 | obj.startswith(foo) or obj.startswith("foo")
9 9 | # error

PIE810.py:8:1: PIE810 [*] Call `startswith` once with a `tuple`
   |
 6 | obj.startswith(foo) or obj.startswith(bar)
 7 | # error
 8 | obj.startswith(foo) or obj.startswith("foo")
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE810
 9 | # error
10 | obj.endswith(foo) or obj.startswith(foo) or obj.startswith("foo")
   |
   = help: Merge into a single `startswith` call

ℹ Unsafe fix
5 5 | # error
6 6 | obj.startswith(foo) or obj.startswith(bar)
7 7 | # error
8   |-obj.startswith(foo) or obj.startswith("foo")
  8 |+obj.startswith((foo, "foo"))
9 9 | # error
10 10 | obj.endswith(foo) or obj.startswith(foo) or obj.startswith("foo")
11 11 | 

PIE810.py:10:1: PIE810 [*] Call `startswith` once with a `tuple`
   |
 8 | obj.startswith(foo) or obj.startswith("foo")
 9 | # error
10 | obj.endswith(foo) or obj.startswith(foo) or obj.startswith("foo")
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE810
11 |
12 | def func():
   |
   = help: Merge into a single `startswith` call

ℹ Unsafe fix
7  7  | # error
8  8  | obj.startswith(foo) or obj.startswith("foo")
9  9  | # error
10    |-obj.endswith(foo) or obj.startswith(foo) or obj.startswith("foo")
   10 |+obj.endswith(foo) or obj.startswith((foo, "foo"))
11 11 | 
12 12 | def func():
13 13 |     msg = "hello world"

PIE810.py:19:8: PIE810 [*] Call `startswith` once with a `tuple`
   |
17 |     z = "w"
18 |
19 |     if msg.startswith(x) or msg.startswith(y) or msg.startswith(z): # Error
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE810
20 |         print("yes") 
   |
   = help: Merge into a single `startswith` call

ℹ Unsafe fix
16 16 |     y = ("h", "e", "l", "l", "o")  
17 17 |     z = "w"
18 18 | 
19    |-    if msg.startswith(x) or msg.startswith(y) or msg.startswith(z): # Error
   19 |+    if msg.startswith((x, z)) or msg.startswith(y): # Error
20 20 |         print("yes") 
21 21 | 
22 22 | def func():

PIE810.py:25:8: PIE810 [*] Call `startswith` once with a `tuple`
   |
23 |     msg = "hello world"
24 |
25 |     if msg.startswith(("h", "e", "l", "l", "o")) or msg.startswith("h") or msg.startswith("w"): # Error
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE810
26 |         print("yes") 
   |
   = help: Merge into a single `startswith` call

ℹ Unsafe fix
22 22 | def func():
23 23 |     msg = "hello world"
24 24 | 
25    |-    if msg.startswith(("h", "e", "l", "l", "o")) or msg.startswith("h") or msg.startswith("w"): # Error
   25 |+    if msg.startswith(("h", "e", "l", "l", "o", "h", "w")): # Error
26 26 |         print("yes") 
27 27 | 
28 28 | # ok

PIE810.py:83:8: PIE810 [*] Call `startswith` once with a `tuple`
   |
81 | def func():
82 |     "Regression test for https://github.com/astral-sh/ruff/issues/9663"
83 |     if x.startswith("a") or x.startswith("b") or re.match(r"a\.b", x):
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE810
84 |         print("yes")
   |
   = help: Merge into a single `startswith` call

ℹ Unsafe fix
80 80 | 
81 81 | def func():
82 82 |     "Regression test for https://github.com/astral-sh/ruff/issues/9663"
83    |-    if x.startswith("a") or x.startswith("b") or re.match(r"a\.b", x):
   83 |+    if x.startswith(("a", "b")) or re.match(r"a\.b", x):
84 84 |         print("yes")
