Skip to content

Commit ccb92f2

Browse files
aatlePierre-Sassoulas
authored andcommitted
Fixed possibly-used-before-assignment by replacing flag variable
1 parent f272ae8 commit ccb92f2

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

pylint/checkers/refactoring/implicit_booleaness_checker.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,20 +209,17 @@ def _check_compare_to_str_or_zero(self, node: nodes.Compare) -> None:
209209
continue
210210
op_1 = all_ops[ops_idx]
211211
op_3 = all_ops[ops_idx + 2]
212-
error_detected = False
213212
if self.linter.is_message_enabled(
214213
"use-implicit-booleaness-not-comparison-to-zero"
215214
):
215+
op = None
216216
# 0 ?? X
217217
if _is_constant_zero(op_1):
218-
error_detected = True
219218
op = op_3
220219
# X ?? 0
221220
elif _is_constant_zero(op_3):
222-
error_detected = True
223221
op = op_1
224-
if error_detected:
225-
# pylint: disable=possibly-used-before-assignment
222+
if op is not None:
226223
original = f"{op_1.as_string()} {op_2} {op_3.as_string()}"
227224
suggestion = (
228225
op.as_string()
@@ -235,20 +232,17 @@ def _check_compare_to_str_or_zero(self, node: nodes.Compare) -> None:
235232
node=node,
236233
confidence=HIGH,
237234
)
238-
error_detected = False
239235
if self.linter.is_message_enabled(
240236
"use-implicit-booleaness-not-comparison-to-str"
241237
):
242-
node_name = ""
238+
node_name = None
243239
# x ?? ""
244240
if utils.is_empty_str_literal(op_1):
245-
error_detected = True
246241
node_name = op_3.as_string()
247242
# '' ?? X
248243
elif utils.is_empty_str_literal(op_3):
249-
error_detected = True
250244
node_name = op_1.as_string()
251-
if error_detected:
245+
if node_name is not None:
252246
suggestion = (
253247
f"not {node_name}" if op_2 in {"==", "is"} else node_name
254248
)

0 commit comments

Comments
 (0)