diff --git a/src/codemodder/codemods/docs/pixee_python_use-walrus-if.md b/src/codemodder/codemods/docs/pixee_python_use-walrus-if.md new file mode 100644 index 00000000..ac03f08b --- /dev/null +++ b/src/codemodder/codemods/docs/pixee_python_use-walrus-if.md @@ -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. diff --git a/src/codemodder/codemods/use_walrus_if.py b/src/codemodder/codemods/use_walrus_if.py index dcd6a49a..e4f1d295 100644 --- a/src/codemodder/codemods/use_walrus_if.py +++ b/src/codemodder/codemods/use_walrus_if.py @@ -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" diff --git a/tests/test_codemod_docs.py b/tests/test_codemod_docs.py index 0d0b35e2..70a93995 100644 --- a/tests/test_codemod_docs.py +++ b/tests/test_codemod_docs.py @@ -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