Skip to content

Commit

Permalink
Add description for walrus codemod
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Sep 25, 2023
1 parent 538aaaf commit 92c2b8a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/codemodder/codemods/docs/pixee_python_use-walrus-if.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
This codemod updates places where two separate statements involving an assignment
and conditional can be replaced with a single Assignment Expression (commonly
known as the walrus operator).

Many developers use this operator in new code that they write but don't have
the time to find and update every place in existing code. So we do it for you!
We believe this leads to more concise and readable code.

The changes from this codemod look like this:

```diff
- x = foo()
- if x is not None:
+ if (x := foo()) is not None:
print(x)
```

The walrus operator is only supported in Python 3.8 and later.
4 changes: 1 addition & 3 deletions src/codemodder/codemods/use_walrus_if.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class UseWalrusIf(SemgrepCodemod, NameResolutionMixin):
ScopeProvider,
)
NAME = "use-walrus-if"
SUMMARY = (
"Replace multiple expressions involving `if` operator with 'walrus' operator"
)
SUMMARY = "Use Assignment Expression in Conditional"
REVIEW_GUIDANCE = ReviewGuidance.MERGE_AFTER_CURSORY_REVIEW
DESCRIPTION = (
"Replaces multiple expressions involving `if` operator with 'walrus' operator"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_codemod_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@pytest.fixture(params=DEFAULT_CODEMODS)
def codemod_name(request):
name = request.param.name()
if name in ["order-imports", "use-walrus-if"]:
if name in ["order-imports"]:
pytest.skip("No docs yet")
return name

Expand Down

0 comments on commit 92c2b8a

Please sign in to comment.