Skip to content

Commit

Permalink
Hardening suggestions for codemodder-python / sqlp-formatop (#362)
Browse files Browse the repository at this point in the history
Use Assignment Expression (Walrus) In Conditional

Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com>
  • Loading branch information
pixeebot[bot] authored and andrecsilva committed Mar 13, 2024
1 parent b804afd commit bdf595d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/codemodder/utils/clean_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ def _handle_target(self, node):
# return node.with_changes(elements = new_elements)
# return None
case cst.Name():
target_acesses = self.find_accesses(node)
if target_acesses:
if target_acesses := self.find_accesses(node):
return node
else:
return None
Expand All @@ -230,8 +229,7 @@ def leave_Assign(

new_targets = []
for target in original_node.targets:
new_target = self._handle_target(target.target)
if new_target:
if new_target := self._handle_target(target.target):
new_targets.append(target.with_changes(target=new_target))
# remove everything
if not new_targets:
Expand Down
5 changes: 2 additions & 3 deletions src/codemodder/utils/format_string_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ def parse_formatted_string(
for piece, piece_parts in parsed_pieces:
match piece:
case cst.SimpleString() | cst.FormattedStringText():
maybe_conversion = _convert_piece_and_parts(
if maybe_conversion := _convert_piece_and_parts(
piece, piece_parts, token_count, keys
)
if maybe_conversion:
):
converted, token_count = maybe_conversion
parts.extend(converted)
else:
Expand Down
3 changes: 1 addition & 2 deletions src/core_codemods/sql_parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ def extract_prefix(self, node: StringLiteralNodeType) -> str:

def _extract_prefix_raw_value(self, node: StringLiteralNodeType) -> tuple[str, str]:
raw_value = extract_raw_value(node)
prefix = self.extract_prefix(node)
if prefix is not None:
if (prefix := self.extract_prefix(node)) is not None:
return prefix, raw_value
return prefix, raw_value

Expand Down

0 comments on commit bdf595d

Please sign in to comment.