chore: Embrace the walrus operator#24127
Conversation
Codecov Report
@@ Coverage Diff @@
## master #24127 +/- ##
==========================================
- Coverage 68.30% 68.26% -0.04%
==========================================
Files 1952 1952
Lines 75432 75388 -44
Branches 8191 8202 +11
==========================================
- Hits 51521 51462 -59
- Misses 21807 21819 +12
- Partials 2104 2107 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
26c722a to
d7e6265
Compare
There was a problem hiding this comment.
Sadly we're stuck between a rock and a hard place here. There is a Pylint false positive on line #265 but if we add the disable comment there then Black will reformat the line because its > 88 characters and the formatting then requires the extra (...) per Pylint's rules.
d7e6265 to
5c89456
Compare
There was a problem hiding this comment.
Probably should reformat the code before running Mypy, Black, etc.
5c89456 to
ed4e4c8
Compare
|
Lol, love the auto walrus! Btw walrus was already added in 3.8, so it's been supported on the codebase for quite some time (3.7 was deprecated here in March 2022: #19017) |
villebro
left a comment
There was a problem hiding this comment.
I browsed through all the changes, and they LGTM. Happy to see this enforced, as I'm also a big fan of the walrus.
SUMMARY
In #23890 (thanks to @sebastianliebscher) we dropped support for Python 3.8 and thus now we are free to embrace the walrus (
:=) operator. This PR adds a pre-commit hook (which runs beforeblack) to ensure we never have code of the form,but rather,
Note the pre-commit hook only detects/remedies simple use cases. Personally I've found the walrus operator really handy in list comprehensions (when you need to assign a temporary variable) and logic like,
which becomes,
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
CI.
ADDITIONAL INFORMATION