Skip to main content

Flake8 plugin for structural pattern matching

Project description

flake8-spm

Flake8 plugin for finding issues with structural pattern matching

NOTE: this plugin is under development. Coming up soon!

Motivation

Structural pattern matching has been introduced in PEP 634 with the tutorial added in PEP 636.

The present plugin intends to catch default cases, which do not match any pattern, but do not raise an exception.

In the problematic example below we handle unexpected pattern as Default.

def func(value):
    match value:
        case 1:
            return 'One'
        case _:
            return 'Default'  # <-- ignoring exceptional case

However, for the non-matching cases we would better raise an error, to follow fail-fast methodology. Indeed, if we could not find a mathing pattern, then it is an unexpected event, and we need to raise an error, as shown below.

def func(value):
    match value:
        case 1:
            return 'One'
        case _:
            raise ValueError(f'Unexpected case: {value}')

Then in the client code we would handle this error appropriately, instead of sweeping the issue under the rug.

List of warnings

SPM001: not raising when matching default value.

Installation (IN PROGRESS)

Install via pip with:

$ pip install flake8-spm

It will then automatically be run as part of flake8. You can check is has been picked up via:

$ flake8 --version

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_spm-0.0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

flake8_spm-0.0.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file flake8_spm-0.0.1.tar.gz.

File metadata

  • Download URL: flake8_spm-0.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for flake8_spm-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f7151b15385bd9d5890be0ae8348cf58424710b345a4ae5bb5d1035570c2b0a9
MD5 1b3c659e1a523701152d394b9c3e9632
BLAKE2b-256 04253228c975a1e39ebeb7ebcdb45d4531cb4f5d11729a0eaa03584273a3f3e9

See more details on using hashes here.

File details

Details for the file flake8_spm-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: flake8_spm-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for flake8_spm-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7013423b5376ab2e04c0d96a7276e99aa218f5db9b397381562d7a6d3da6c9fb
MD5 e9374604d893cf0ab41c57977e52b31f
BLAKE2b-256 715f175e8041426fb3077c7e1968bb7c9d31bd3c921969dcdfb75f0b48850fdd

See more details on using hashes here.

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