Skip to content

Conversation

@pixeebot
Copy link
Contributor

@pixeebot pixeebot bot commented Feb 15, 2025

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

Feedback | Community | Docs | Codemod ID: pixee:python/use-walrus-if

@drdavella drdavella force-pushed the pixeebot/drip-2025-02-15-pixee-python/use-walrus-if branch from 6a28166 to a67ead6 Compare February 20, 2025 14:37
@sonarqubecloud
Copy link

@drdavella drdavella added this pull request to the merge queue Feb 20, 2025
Merged via the queue into main with commit 76220b4 Feb 20, 2025
15 checks passed
@drdavella drdavella deleted the pixeebot/drip-2025-02-15-pixee-python/use-walrus-if branch February 20, 2025 19:56
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.

1 participant