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

Add description for walrus codemod #44

Merged
merged 1 commit into from
Sep 25, 2023
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
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