Skip to content

Commit 76220b4

Browse files
Use Assignment Expression (Walrus) In Conditional (#998)
* Use Assignment Expression (Walrus) In Conditional * 🎨 Apply formatting --------- Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com>
1 parent 0e3722f commit 76220b4

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/codemodder/codemodder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ def apply_codemods(
8989
for codemod in codemods_to_run:
9090
# NOTE: this may be used as a progress indicator by upstream tools
9191
logger.info("running codemod %s", codemod.id)
92-
codemod_token_usage = codemod.apply(context)
93-
if codemod_token_usage:
92+
if codemod_token_usage := codemod.apply(context):
9493
log_token_usage(f"Codemod {codemod.id}", codemod_token_usage)
9594
token_usage += codemod_token_usage
9695

src/codemodder/codemods/utils_mixin.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ def class_has_method(self, classdef: cst.ClassDef, method_name: str) -> bool:
308308
"""Check if a given class definition implements a method of name `method_name`."""
309309
for node in classdef.body.body:
310310
match node:
311-
case cst.FunctionDef(
312-
name=cst.Name(value=value)
313-
) if value == method_name:
311+
case cst.FunctionDef(name=cst.Name(value=value)) if (
312+
value == method_name
313+
):
314314
return True
315315
return False
316316

@@ -331,7 +331,9 @@ def is_value_of_assignment(
331331
| cst.Assign(value=value)
332332
| cst.WithItem(item=value)
333333
| cst.NamedExpr(value=value)
334-
) if expr == value: # type: ignore
334+
) if (
335+
expr == value
336+
): # type: ignore
335337
return parent
336338
return None
337339

src/codemodder/utils/format_string_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def expressions_from_replacements(
128128

129129

130130
def dict_to_values_dict(
131-
expr_dict: dict[cst.BaseExpression, cst.BaseExpression]
131+
expr_dict: dict[cst.BaseExpression, cst.BaseExpression],
132132
) -> dict[str | cst.BaseExpression, cst.BaseExpression]:
133133
return {
134134
extract_raw_value(k): v

0 commit comments

Comments
 (0)