Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardening suggestions for codemodder-python / sqlp-formatop #362

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaces multiple expressions involving if operator with 'walrus' operator.

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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaces multiple expressions involving if operator with 'walrus' operator.

# 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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaces multiple expressions involving if operator with 'walrus' operator.

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:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaces multiple expressions involving if operator with 'walrus' operator.

return prefix, raw_value
return prefix, raw_value

Expand Down