---
source: crates/ruff_linter/src/rules/flake8_pie/mod.rs
---
PIE810 [*] Call `startswith` once with a `tuple`
 --> PIE810.py:2:1
  |
1 | # error
2 | obj.startswith("foo") or obj.startswith("bar")
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 | # error
4 | obj.endswith("foo") or obj.endswith("bar")
  |
help: Merge into a single `startswith` call
  |
1 | # error
  - obj.startswith("foo") or obj.startswith("bar")
2 + obj.startswith(("foo", "bar"))
3 | # error
  |
note: This is an unsafe fix and may change runtime behavior

PIE810 [*] Call `endswith` once with a `tuple`
 --> PIE810.py:4:1
  |
2 | obj.startswith("foo") or obj.startswith("bar")
3 | # error
4 | obj.endswith("foo") or obj.endswith("bar")
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 | # error
6 | obj.startswith(foo) or obj.startswith(bar)
  |
help: Merge into a single `endswith` call
  |
3 | # error
  - obj.endswith("foo") or obj.endswith("bar")
4 + obj.endswith(("foo", "bar"))
5 | # error
  |
note: This is an unsafe fix and may change runtime behavior

PIE810 [*] Call `startswith` once with a `tuple`
 --> PIE810.py:6:1
  |
4 | obj.endswith("foo") or obj.endswith("bar")
5 | # error
6 | obj.startswith(foo) or obj.startswith(bar)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7 | # error
8 | obj.startswith(foo) or obj.startswith("foo")
  |
help: Merge into a single `startswith` call
  |
5 | # error
  - obj.startswith(foo) or obj.startswith(bar)
6 + obj.startswith((foo, bar))
7 | # error
  |
note: This is an unsafe fix and may change runtime behavior

PIE810 [*] Call `startswith` once with a `tuple`
  --> PIE810.py:8:1
   |
 6 | obj.startswith(foo) or obj.startswith(bar)
 7 | # error
 8 | obj.startswith(foo) or obj.startswith("foo")
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 9 | # error
10 | obj.endswith(foo) or obj.startswith(foo) or obj.startswith("foo")
   |
help: Merge into a single `startswith` call
  |
7 | # error
  - obj.startswith(foo) or obj.startswith("foo")
8 + obj.startswith((foo, "foo"))
9 | # error
  |
note: This is an unsafe fix and may change runtime behavior

PIE810 [*] Call `startswith` once with a `tuple`
  --> PIE810.py:10:1
   |
 8 | obj.startswith(foo) or obj.startswith("foo")
 9 | # error
10 | obj.endswith(foo) or obj.startswith(foo) or obj.startswith("foo")
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11 |
12 | def func():
   |
help: Merge into a single `startswith` call
   |
9  | # error
   - obj.endswith(foo) or obj.startswith(foo) or obj.startswith("foo")
10 + obj.endswith(foo) or obj.startswith((foo, "foo"))
11 |
   |
note: This is an unsafe fix and may change runtime behavior

PIE810 [*] Call `startswith` once with a `tuple`
  --> PIE810.py:19:8
   |
17 |     z = "w"
18 |
19 |     if msg.startswith(x) or msg.startswith(y) or msg.startswith(z): # Error
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20 |         print("yes") 
   |
help: Merge into a single `startswith` call
   |
18 |
   -     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 |         print("yes") 
   |
note: This is an unsafe fix and may change runtime behavior

PIE810 [*] Call `startswith` once with a `tuple`
  --> PIE810.py:25:8
   |
23 |     msg = "hello world"
24 |
25 |     if msg.startswith(("h", "e", "l", "l", "o")) or msg.startswith("h") or msg.startswith("w"): # Error
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26 |         print("yes") 
   |
help: Merge into a single `startswith` call
   |
24 |
   -     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 |         print("yes") 
   |
note: This is an unsafe fix and may change runtime behavior

PIE810 [*] Call `startswith` once with a `tuple`
  --> PIE810.py:83:8
   |
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):
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
84 |         print("yes")
   |
help: Merge into a single `startswith` call
   |
82 |     "Regression test for https://github.com/astral-sh/ruff/issues/9663"
   -     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 |         print("yes")
   |
note: This is an unsafe fix and may change runtime behavior
