auto-walrus
auto-walrus
A tool and pre-commit hook to automatically apply the awesome walrus operator.
Installation
pip install auto-walrus
Usage as a pre-commit hook
See pre-commit for instructions
Sample .pre-commit-config.yaml:
- repo: https://github.com/MarcoGorelli/auto-walrus
rev: 0.4.1
hooks:
- id: auto-walrus
Command-line example
auto-walrus myfile.py
- n = 10
- if n > 3:
+ if (n := 10) > 3:
print(n)
Configuration
Using the walrus operator can result in longer lines. Lines longer than what you
pass to --line-length won't be rewritten to use walrus operators.
E.g.
auto-walrus myfile_1.py myfile_2.py --line-length 89
Lines with comments won't be rewritten.
Used by
To my great surprise, this is being used by:
- https://github.com/python-graphblas/python-graphblas
- https://github.com/Remi-Gau/bids2cite
- https://github.com/TheAlgorithms/Python
- https://github.com/apache/superset
Anyone else? Please let me know, or you can open a pull request to add yourself.
Testimonials
Christopher Redwine, Senior Software Engineer at TechnologyAdvice
hmm, i dunno about this one chief
Michael Kennedy & Brian Okken, hosts of the Python Bytes podcast:
I kind of like this being separate from other tools
Someone on Discord
you're a monster
Will McGugan, CEO / Founder of http://Textualize.io:
Embrace the Walrus!
Credits
Logo by lion_space
Release files for auto-walrus 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| auto_walrus-0.4.1.tar.gz | 10.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| auto_walrus-0.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.3 kB
Release files / auto_walrus-0.4.1.tar.gz
| Download URL | auto_walrus-0.4.1.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9874ab07597dc2cc78a30fca944f6a9e6bee0033645e659ac9337a219691662f
|
|
BLAKE2b-256 checksum How to use checksums |
97529a7484513537f4c469ecbef28be339e364f3b3da116a5ad6078af27b59b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 2, 2026.
Transparency logRelease files / auto_walrus-0.4.1-py3-none-any.whl
| Download URL | auto_walrus-0.4.1-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
53bda8558708dcd67b2205212acafec7c12543dec0bd7f84f9f2207f4b6e6d52
|
|
BLAKE2b-256 checksum How to use checksums |
1e959ee7a9e668f47395a431514543d6a8a452998415738b48c92cc9edf14c57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 2, 2026.
Transparency log