-
Notifications
You must be signed in to change notification settings - Fork 10
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaces multiple expressions involving |
||
# remove everything | ||
if not new_targets: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaces multiple expressions involving |
||
piece, piece_parts, token_count, keys | ||
) | ||
if maybe_conversion: | ||
): | ||
converted, token_count = maybe_conversion | ||
parts.extend(converted) | ||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaces multiple expressions involving |
||
return prefix, raw_value | ||
return prefix, raw_value | ||
|
||
|
There was a problem hiding this comment.
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.