Automatically apply the awesome walrus operator
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file auto_walrus-0.4.1.tar.gz.
File metadata
- Download URL: auto_walrus-0.4.1.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9874ab07597dc2cc78a30fca944f6a9e6bee0033645e659ac9337a219691662f
|
|
| MD5 |
cdc373e826bcd45181b35cef20622ff3
|
|
| BLAKE2b-256 |
97529a7484513537f4c469ecbef28be339e364f3b3da116a5ad6078af27b59b2
|
Provenance
The following attestation bundles were made for auto_walrus-0.4.1.tar.gz:
Publisher:
publish_to_pypi.yml on MarcoGorelli/auto-walrus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
auto_walrus-0.4.1.tar.gz -
Subject digest:
9874ab07597dc2cc78a30fca944f6a9e6bee0033645e659ac9337a219691662f - Sigstore transparency entry: 904510539
- Sigstore integration time:
-
Permalink:
MarcoGorelli/auto-walrus@d376c6a49feac78bc2115bf3df7e862629cce612 -
Branch / Tag:
refs/tags/0.4.1 - Owner: https://github.com/MarcoGorelli
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_to_pypi.yml@d376c6a49feac78bc2115bf3df7e862629cce612 -
Trigger Event:
push
-
Statement type:
File details
Details for the file auto_walrus-0.4.1-py3-none-any.whl.
File metadata
- Download URL: auto_walrus-0.4.1-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53bda8558708dcd67b2205212acafec7c12543dec0bd7f84f9f2207f4b6e6d52
|
|
| MD5 |
588b1c6760e63f8465ec06f8c0409018
|
|
| BLAKE2b-256 |
1e959ee7a9e668f47395a431514543d6a8a452998415738b48c92cc9edf14c57
|
Provenance
The following attestation bundles were made for auto_walrus-0.4.1-py3-none-any.whl:
Publisher:
publish_to_pypi.yml on MarcoGorelli/auto-walrus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
auto_walrus-0.4.1-py3-none-any.whl -
Subject digest:
53bda8558708dcd67b2205212acafec7c12543dec0bd7f84f9f2207f4b6e6d52 - Sigstore transparency entry: 904510598
- Sigstore integration time:
-
Permalink:
MarcoGorelli/auto-walrus@d376c6a49feac78bc2115bf3df7e862629cce612 -
Branch / Tag:
refs/tags/0.4.1 - Owner: https://github.com/MarcoGorelli
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_to_pypi.yml@d376c6a49feac78bc2115bf3df7e862629cce612 -
Trigger Event:
push
-
Statement type: