dtiesling / flask-muck

🧹 Flask REST framework for generating CRUD APIs and OpenAPI specs in the SQLAlchemy, Marshmallow/Pydantic application stack.
https://dtiesling.github.io/flask-muck/
MIT License
158 stars 7 forks source link

style: use walrus in conditional #56

Closed pixeebot[bot] closed 7 months ago

pixeebot[bot] commented 7 months ago

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 * [https://docs.python.org/3/whatsnew/3.8.html#assignment-expressions](https://docs.python.org/3/whatsnew/3.8.html#assignment-expressions)

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 commented 7 months ago

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