-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
20 additions
and
4 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/codemodder/codemods/docs/pixee_python_use-walrus-if.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters