Skip to main content

A flake8 plugin that disallows assignment expressions

Project description

flake8_expression_assignments

A flake8 plugin that disallows assignment expressions.

Installation

pip install flake8_assignment_expressions

Flake8 codes

Code Description
ASE101 Line contains assignment expression

Why

Assignment expressions/the walrus operator was introduced in Python 3.8. If you want to keep assignment expressions out of your own or your companies' repositories, use this plugin.

This plugin will encourage you to rewrite code like

import os

if environment := os.getenv("ENVIRONMENT"):
    print(f"You are currently on the {environment} environment.")

into

import os

environment = os.getenv("ENVIRONMENT")
if environment:
    print(f"You are currently on the {environment} environment.")

Running as a pre-commit hook

See pre-commit for instructions.

Sample .pre-commit-config.yaml:

-   repo: https://github.com/pycqa/flake8
    rev: 4.0.1
    hooks:
    -   id: flake8
        additional_dependencies: [flake8_assignment_expressions]

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

flake8_assignment_expressions-1.0.0.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

Supported by

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