---
source: crates/ruff_linter/src/rules/flake8_simplify/mod.rs
---
SIM114 [*] Combine `if` branches using logical `or` operator
 --> SIM114.py:2:1
  |
1 |   # Errors
2 | / if a:
3 | |     b
4 | | elif c:
5 | |     b
  | |_____^
6 |
7 |   if a:  # we preserve comments, too!
  |
help: Combine `if` branches
  |
1 | # Errors
  - if a:
  -     b
  - elif c:
2 + if a or c:
3 |     b
  |

SIM114 [*] Combine `if` branches using logical `or` operator
  --> SIM114.py:7:1
   |
 5 |       b
 6 |
 7 | / if a:  # we preserve comments, too!
 8 | |     b
 9 | | elif c:  # but not on the second branch
10 | |     b
   | |_____^
11 |
12 |   if x == 1:
   |
help: Combine `if` branches
  |
6 |
  - if a:  # we preserve comments, too!
  -     b
  - elif c:  # but not on the second branch
7 + if a or c:  # we preserve comments, too!
8 |     b
  |

SIM114 [*] Combine `if` branches using logical `or` operator
  --> SIM114.py:12:1
   |
10 |       b
11 |
12 | / if x == 1:
13 | |     for _ in range(20):
14 | |         print("hello")
15 | | elif x == 2:
16 | |     for _ in range(20):
17 | |         print("hello")
   | |______________________^
18 |
19 |   if x == 1:
   |
help: Combine `if` branches
   |
11 |
   - if x == 1:
   -     for _ in range(20):
   -         print("hello")
   - elif x == 2:
12 + if x == 1 or x == 2:
13 |     for _ in range(20):
   |

SIM114 [*] Combine `if` branches using logical `or` operator
  --> SIM114.py:19:1
   |
17 |           print("hello")
18 |
19 | / if x == 1:
20 | |     if True:
21 | |         for _ in range(20):
22 | |             print("hello")
23 | | elif x == 2:
24 | |     if True:
25 | |         for _ in range(20):
26 | |             print("hello")
   | |__________________________^
27 |
28 |   if x == 1:
   |
help: Combine `if` branches
   |
18 |
   - if x == 1:
   -     if True:
   -         for _ in range(20):
   -             print("hello")
   - elif x == 2:
19 + if x == 1 or x == 2:
20 |     if True:
   |

SIM114 [*] Combine `if` branches using logical `or` operator
  --> SIM114.py:28:1
   |
26 |               print("hello")
27 |
28 | / if x == 1:
29 | |     if True:
30 | |         for _ in range(20):
31 | |             print("hello")
32 | |     elif False:
33 | |         for _ in range(20):
34 | |             print("hello")
35 | | elif x == 2:
36 | |     if True:
37 | |         for _ in range(20):
38 | |             print("hello")
39 | |     elif False:
40 | |         for _ in range(20):
41 | |             print("hello")
   | |__________________________^
42 |
43 |   if (
   |
help: Combine `if` branches
   |
27 |
   - if x == 1:
   -     if True:
   -         for _ in range(20):
   -             print("hello")
   -     elif False:
   -         for _ in range(20):
   -             print("hello")
   - elif x == 2:
28 + if x == 1 or x == 2:
29 |     if True:
   |

SIM114 [*] Combine `if` branches using logical `or` operator
  --> SIM114.py:29:5
   |
28 |   if x == 1:
29 | /     if True:
30 | |         for _ in range(20):
31 | |             print("hello")
32 | |     elif False:
33 | |         for _ in range(20):
34 | |             print("hello")
   | |__________________________^
35 |   elif x == 2:
36 |       if True:
   |
help: Combine `if` branches
   |
28 | if x == 1:
   -     if True:
   -         for _ in range(20):
   -             print("hello")
   -     elif False:
29 +     if True or False:
30 |         for _ in range(20):
   |

SIM114 [*] Combine `if` branches using logical `or` operator
  --> SIM114.py:36:5
   |
34 |               print("hello")
35 |   elif x == 2:
36 | /     if True:
37 | |         for _ in range(20):
38 | |             print("hello")
39 | |     elif False:
40 | |         for _ in range(20):
41 | |             print("hello")
   | |__________________________^
42 |
43 |   if (
   |
help: Combine `if` branches
   |
35 | elif x == 2:
   -     if True:
   -         for _ in range(20):
   -             print("hello")
   -     elif False:
36 +     if True or False:
37 |         for _ in range(20):
   |

SIM114 [*] Combine `if` branches using logical `or` operator
  --> SIM114.py:43:1
   |
41 |               print("hello")
42 |
43 | / if (
44 | |     x == 1
45 | |     and y == 2
46 | |     and z == 3
47 | |     and a == 4
48 | |     and b == 5
49 | |     and c == 6
50 | |     and d == 7
51 | |     and e == 8
52 | |     and f == 9
53 | |     and g == 10
54 | |     and h == 11
55 | |     and i == 12
56 | |     and j == 13
57 | |     and k == 14
58 | | ):
59 | |     pass
60 | | elif 1 == 2:
61 | |     pass
   | |________^
62 |
63 |   if result.eofs == "O":
   |
help: Combine `if` branches
   |
57 |     and k == 14
   - ):
   -     pass
   - elif 1 == 2:
58 + ) or 1 == 2:
59 |     pass
   |

SIM114 [*] Combine `if` branches using logical `or` operator
  --> SIM114.py:67:1
   |
65 |   elif result.eofs == "S":
66 |       skipped = 1
67 | / elif result.eofs == "F":
68 | |     errors = 1
69 | | elif result.eofs == "E":
70 | |     errors = 1
   | |______________^
71 |   elif result.eofs == "X":
72 |       errors = 1
   |
help: Combine `if` branches
   |
66 |     skipped = 1
   - elif result.eofs == "F":
   -     errors = 1
   - elif result.eofs == "E":
67 + elif result.eofs == "F" or result.eofs == "E":
68 |     errors = 1
   |

SIM114 [*] Combine `if` branches using logical `or` operator
  --> SIM114.py:69:1
   |
67 |   elif result.eofs == "F":
68 |       errors = 1
69 | / elif result.eofs == "E":
70 | |     errors = 1
71 | | elif result.eofs == "X":
72 | |     errors = 1
   | |______________^
73 |   elif result.eofs == "C":
74 |       errors = 1
   |
help: Combine `if` branches
   |
68 |     errors = 1
   - elif result.eofs == "E":
   -     errors = 1
   - elif result.eofs == "X":
69 + elif result.eofs == "E" or result.eofs == "X":
70 |     errors = 1
   |

SIM114 [*] Combine `if` branches using logical `or` operator
  --> SIM114.py:71:1
   |
69 |   elif result.eofs == "E":
70 |       errors = 1
71 | / elif result.eofs == "X":
72 | |     errors = 1
73 | | elif result.eofs == "C":
74 | |     errors = 1
   | |______________^
   |
help: Combine `if` branches
   |
70 |     errors = 1
   - elif result.eofs == "X":
   -     errors = 1
   - elif result.eofs == "C":
71 + elif result.eofs == "X" or result.eofs == "C":
72 |     errors = 1
   |

SIM114 [*] Combine `if` branches using logical `or` operator
   --> SIM114.py:118:5
    |
116 |       a = True
117 |       b = False
118 | /     if a > b:  # end-of-line
119 | |         return 3
120 | |     elif a == b:
121 | |         return 3
    | |________________^
122 |       elif a < b:  # end-of-line
123 |           return 4
    |
help: Combine `if` branches
    |
117 |     b = False
    -     if a > b:  # end-of-line
    -         return 3
    -     elif a == b:
118 +     if a > b or a == b:  # end-of-line
119 |         return 3
    |

SIM114 [*] Combine `if` branches using logical `or` operator
   --> SIM114.py:122:5
    |
120 |       elif a == b:
121 |           return 3
122 | /     elif a < b:  # end-of-line
123 | |         return 4
124 | |     elif b is None:
125 | |         return 4
    | |________________^
    |
help: Combine `if` branches
    |
121 |         return 3
    -     elif a < b:  # end-of-line
    -         return 4
    -     elif b is None:
122 +     elif a < b or b is None:  # end-of-line
123 |         return 4
    |

SIM114 [*] Combine `if` branches using logical `or` operator
   --> SIM114.py:132:5
    |
130 |       a = True
131 |       b = False
132 | /     if a > b:  # end-of-line
133 | |         return 3
134 | |     elif a := 1:
135 | |         return 3
    | |________________^
    |
help: Combine `if` branches
    |
131 |     b = False
    -     if a > b:  # end-of-line
    -         return 3
    -     elif a := 1:
132 +     if a > b or (a := 1):  # end-of-line
133 |         return 3
    |

SIM114 [*] Combine `if` branches using logical `or` operator
   --> SIM114.py:138:1
    |
138 | / if a:  # we preserve comments, too!
139 | |     b
140 | | elif c:  # but not on the second branch
141 | |     b
    | |_____^
    |
help: Combine `if` branches
    |
137 |
    - if a:  # we preserve comments, too!
    -     b
    - elif c:  # but not on the second branch
138 + if a or c:  # we preserve comments, too!
139 |     b
    |

SIM114 [*] Combine `if` branches using logical `or` operator
   --> SIM114.py:144:1
    |
144 | / if a: b  # here's a comment
145 | | elif c: b
    | |_________^
    |
help: Combine `if` branches
    |
143 |
    - if a: b  # here's a comment
    - elif c: b
144 + if a or c: b  # here's a comment
145 |
    |

SIM114 [*] Combine `if` branches using logical `or` operator
   --> SIM114.py:148:1
    |
148 | / if(x > 200): pass
149 | | elif(100 < x and x < 200 and 300 < y and y < 800):
150 | |     pass
    | |________^
    |
help: Combine `if` branches
    |
147 |
    - if(x > 200): pass
    - elif(100 < x and x < 200 and 300 < y and y < 800):
    - 	pass
148 + if(x > 200) or (100 < x and x < 200 and 300 < y and y < 800): pass
149 |
    |

SIM114 [*] Combine `if` branches using logical `or` operator
   --> SIM114.py:154:1
    |
153 |   # See: https://github.com/astral-sh/ruff/issues/12732
154 | / if False if True else False:
155 | |     print(1)
156 | | elif True:
157 | |     print(1)
    | |____________^
158 |   else:
159 |       print(2)
    |
help: Combine `if` branches
    |
153 | # See: https://github.com/astral-sh/ruff/issues/12732
    - if False if True else False:
    -     print(1)
    - elif True:
154 + if (False if True else False) or True:
155 |     print(1)
    |
