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

style: use walrus in conditional #56

Merged
merged 2 commits into from
Feb 8, 2024

Conversation

pixeebot[bot]
Copy link
Contributor

@pixeebot pixeebot bot commented Feb 8, 2024

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

I have additional improvements ready for this repo! If you want to see them, leave the comment:

@pixeebot next

... and I will open a new PR right away!

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

@dtiesling dtiesling changed the title Use Assignment Expression (Walrus) In Conditional style: use walrus in conditional Feb 8, 2024
@dtiesling dtiesling merged commit b9e5f98 into main Feb 8, 2024
3 checks passed
@dtiesling dtiesling deleted the pixeebot/drip-2024-02-08-pixee-python/use-walrus-if branch February 8, 2024 08:04
@dtiesling
Copy link
Owner

My @pixeebot PR got merged and I got swag! pixee.ai/swag

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.

2 participants