Skip to main content

Automatically apply the awesome walrus operator

Project description

auto-walrus

auto-walrus

auto-walrus

Build Status Coverage pre-commit.ci status

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:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

auto_walrus-0.4.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

auto_walrus-0.4.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

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

Hashes for auto_walrus-0.4.1.tar.gz
Algorithm Hash digest
SHA256 9874ab07597dc2cc78a30fca944f6a9e6bee0033645e659ac9337a219691662f
MD5 cdc373e826bcd45181b35cef20622ff3
BLAKE2b-256 97529a7484513537f4c469ecbef28be339e364f3b3da116a5ad6078af27b59b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for auto_walrus-0.4.1.tar.gz:

Publisher: publish_to_pypi.yml on MarcoGorelli/auto-walrus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for auto_walrus-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 53bda8558708dcd67b2205212acafec7c12543dec0bd7f84f9f2207f4b6e6d52
MD5 588b1c6760e63f8465ec06f8c0409018
BLAKE2b-256 1e959ee7a9e668f47395a431514543d6a8a452998415738b48c92cc9edf14c57

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page