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

ℹ Safe fix
1 1 | # Errors
2   |-if a:
3   |-    b
4   |-elif c:
  2 |+if a or c:
5 3 |     b
6 4 | 
7 5 | if a:  # we preserve comments, too!

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

ℹ Safe fix
4  4  | elif c:
5  5  |     b
6  6  | 
7     |-if a:  # we preserve comments, too!
8     |-    b
9     |-elif c:  # but not on the second branch
   7  |+if a or c:  # we preserve comments, too!
10 8  |     b
11 9  | 
12 10 | if x == 1:

SIM114.py:12:1: SIM114 [*] Combine `if` branches using logical `or` operator
   |
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")
   | |______________________^ SIM114
18 |   
19 |   if x == 1:
   |
   = help: Combine `if` branches

ℹ Safe fix
9  9  | elif c:  # but not on the second branch
10 10 |     b
11 11 | 
12    |-if x == 1:
13    |-    for _ in range(20):
14    |-        print("hello")
15    |-elif x == 2:
   12 |+if x == 1 or x == 2:
16 13 |     for _ in range(20):
17 14 |         print("hello")
18 15 | 

SIM114.py:19:1: SIM114 [*] Combine `if` branches using logical `or` operator
   |
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")
   | |__________________________^ SIM114
27 |   
28 |   if x == 1:
   |
   = help: Combine `if` branches

ℹ Safe fix
16 16 |     for _ in range(20):
17 17 |         print("hello")
18 18 | 
19    |-if x == 1:
20    |-    if True:
21    |-        for _ in range(20):
22    |-            print("hello")
23    |-elif x == 2:
   19 |+if x == 1 or x == 2:
24 20 |     if True:
25 21 |         for _ in range(20):
26 22 |             print("hello")

SIM114.py:28:1: SIM114 [*] Combine `if` branches using logical `or` operator
   |
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")
   | |__________________________^ SIM114
42 |   
43 |   if (
   |
   = help: Combine `if` branches

ℹ Safe fix
25 25 |         for _ in range(20):
26 26 |             print("hello")
27 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:
   28 |+if x == 1 or x == 2:
36 29 |     if True:
37 30 |         for _ in range(20):
38 31 |             print("hello")

SIM114.py:29:5: SIM114 [*] Combine `if` branches using logical `or` operator
   |
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")
   | |__________________________^ SIM114
35 |   elif x == 2:
36 |       if True:
   |
   = help: Combine `if` branches

ℹ Safe fix
26 26 |             print("hello")
27 27 | 
28 28 | if x == 1:
29    |-    if True:
30    |-        for _ in range(20):
31    |-            print("hello")
32    |-    elif False:
   29 |+    if True or False:
33 30 |         for _ in range(20):
34 31 |             print("hello")
35 32 | elif x == 2:

SIM114.py:36:5: SIM114 [*] Combine `if` branches using logical `or` operator
   |
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")
   | |__________________________^ SIM114
42 |   
43 |   if (
   |
   = help: Combine `if` branches

ℹ Safe fix
33 33 |         for _ in range(20):
34 34 |             print("hello")
35 35 | elif x == 2:
36    |-    if True:
37    |-        for _ in range(20):
38    |-            print("hello")
39    |-    elif False:
   36 |+    if True or False:
40 37 |         for _ in range(20):
41 38 |             print("hello")
42 39 | 

SIM114.py:43:1: SIM114 [*] Combine `if` branches using logical `or` operator
   |
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
   | |________^ SIM114
62 |   
63 |   if result.eofs == "O":
   |
   = help: Combine `if` branches

ℹ Safe fix
55 55 |     and i == 12
56 56 |     and j == 13
57 57 |     and k == 14
58    |-):
59    |-    pass
60    |-elif 1 == 2:
   58 |+) or 1 == 2:
61 59 |     pass
62 60 | 
63 61 | if result.eofs == "O":

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

ℹ Safe fix
64 64 |     pass
65 65 | elif result.eofs == "S":
66 66 |     skipped = 1
67    |-elif result.eofs == "F":
68    |-    errors = 1
69    |-elif result.eofs == "E":
   67 |+elif result.eofs == "F" or result.eofs == "E":
70 68 |     errors = 1
71 69 | elif result.eofs == "X":
72 70 |     errors = 1

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

ℹ Safe fix
66 66 |     skipped = 1
67 67 | elif result.eofs == "F":
68 68 |     errors = 1
69    |-elif result.eofs == "E":
70    |-    errors = 1
71    |-elif result.eofs == "X":
   69 |+elif result.eofs == "E" or result.eofs == "X":
72 70 |     errors = 1
73 71 | elif result.eofs == "C":
74 72 |     errors = 1

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

ℹ Safe fix
68 68 |     errors = 1
69 69 | elif result.eofs == "E":
70 70 |     errors = 1
71    |-elif result.eofs == "X":
72    |-    errors = 1
73    |-elif result.eofs == "C":
   71 |+elif result.eofs == "X" or result.eofs == "C":
74 72 |     errors = 1
75 73 | 
76 74 | 

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

ℹ Safe fix
115 115 | def func():
116 116 |     a = True
117 117 |     b = False
118     |-    if a > b:  # end-of-line
119     |-        return 3
120     |-    elif a == b:
    118 |+    if a > b or a == b:  # end-of-line
121 119 |         return 3
122 120 |     elif a < b:  # end-of-line
123 121 |         return 4

SIM114.py:122:5: SIM114 [*] Combine `if` branches using logical `or` operator
    |
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
    | |________________^ SIM114
    |
    = help: Combine `if` branches

ℹ Safe fix
119 119 |         return 3
120 120 |     elif a == b:
121 121 |         return 3
122     |-    elif a < b:  # end-of-line
123     |-        return 4
124     |-    elif b is None:
    122 |+    elif a < b or b is None:  # end-of-line
125 123 |         return 4
126 124 | 
127 125 | 

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

ℹ Safe fix
129 129 |     """Ensure that the named expression is parenthesized when merged."""
130 130 |     a = True
131 131 |     b = False
132     |-    if a > b:  # end-of-line
133     |-        return 3
134     |-    elif a := 1:
    132 |+    if a > b or (a := 1):  # end-of-line
135 133 |         return 3
136 134 | 
137 135 | 

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

ℹ Safe fix
135 135 |         return 3
136 136 | 
137 137 | 
138     |-if a:  # we preserve comments, too!
139     |-    b
140     |-elif c:  # but not on the second branch
    138 |+if a or c:  # we preserve comments, too!
141 139 |     b
142 140 | 
143 141 | 

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

ℹ Safe fix
141 141 |     b
142 142 | 
143 143 | 
144     |-if a: b  # here's a comment
145     |-elif c: b
    144 |+if a or c: b  # here's a comment
146 145 | 
147 146 | 
148 147 | if(x > 200): pass

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

ℹ Safe fix
145 145 | elif c: b
146 146 | 
147 147 | 
148     |-if(x > 200): pass
149     |-elif(100 < x and x < 200 and 300 < y and y < 800):
150     |-	pass
    148 |+if(x > 200) or (100 < x and x < 200 and 300 < y and y < 800): pass


