Skip to content

Commit

Permalink
Fixed possibly-used-before-assignment by replacing flag variable
Browse files Browse the repository at this point in the history
  • Loading branch information
aatle committed May 18, 2024
1 parent 16c6819 commit 834cc9a
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions pylint/checkers/refactoring/implicit_booleaness_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,17 @@ def _check_compare_to_str_or_zero(self, node: nodes.Compare) -> None:
continue
op_1 = all_ops[ops_idx]
op_3 = all_ops[ops_idx + 2]
error_detected = False
if self.linter.is_message_enabled(
"use-implicit-booleaness-not-comparison-to-zero"
):
op = None
# 0 ?? X
if _is_constant_zero(op_1):
error_detected = True
op = op_3
# X ?? 0
elif _is_constant_zero(op_3):
error_detected = True
op = op_1
if error_detected:
# pylint: disable=possibly-used-before-assignment
if op is not None:
original = f"{op_1.as_string()} {op_2} {op_3.as_string()}"
suggestion = (
op.as_string()
Expand All @@ -235,20 +232,17 @@ def _check_compare_to_str_or_zero(self, node: nodes.Compare) -> None:
node=node,
confidence=HIGH,
)
error_detected = False
if self.linter.is_message_enabled(
"use-implicit-booleaness-not-comparison-to-str"
):
node_name = ""
node_name = None
# x ?? ""
if utils.is_empty_str_literal(op_1):
error_detected = True
node_name = op_3.as_string()
# '' ?? X
elif utils.is_empty_str_literal(op_3):
error_detected = True
node_name = op_1.as_string()
if error_detected:
if node_name is not None:
suggestion = (
f"not {node_name}" if op_2 in {"==", "is"} else node_name
)
Expand Down

0 comments on commit 834cc9a

Please sign in to comment.