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

Use Assignment Expression (Walrus) In Conditional #8

Merged

Conversation

pixeebot[bot]
Copy link

@pixeebot pixeebot bot commented Dec 19, 2023

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:

- 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.

More reading

Powered by: pixeebot (codemod ID: pixee:python/use-walrus-if)

Copy link
Author

pixeebot bot commented Dec 26, 2023

I'm confident in this change, but I'm not a maintainer of this project. Do you see any reason not to merge it?

If this change was not helpful, or you have suggestions for improvements, please let me know!

@ducttrn ducttrn merged commit 30989d7 into master Jan 2, 2024
4 checks passed
@pixeebot pixeebot bot deleted the pixeebot/drip-2023-12-19-pixee-python/use-walrus-if branch January 2, 2024 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants