Apology of the walrus operator
Python walrus operator has been a source of controversy in the community. Let's list a few of its use cases.
Conditions
if (status := subsystem.Something().status).is_success():
return status
pytest
Provide an informative assertion error message in pytest
.
def test_something():
assert (
response := requests.get(...)
).json() == {'foo': 'bar'}, response.text
Antipatterns
- ≔ + λ
Linters?
What do we have on linters' front about walrus?
Parallels
let
in Rust- Monads?