Skip to main content

A mypy plugin that adds support for checking pure functions.

Project description

mypy-pure

A mypy plugin that enforces purity in Python functions.

Disclaimer

This project has been created using the support of the following AI tools:

  • ChatGPT
  • Antigravity (Gemini)

After that, it has been manually reviewed and fixed.

What is a Pure Function?

A pure function is a function that has the following properties:

  1. Deterministic: Its return value is the same for the same arguments.
  2. No Side Effects: It does not cause any observable side effects (e.g., modifying global variables, I/O operations, database writes).

This mypy plugin helps enforcing statically the second property by detecting calls to known impure functions within functions decorated with @pure.

Installation

Install:

pip install mypy-pure

Enable it in your mypy.ini:

[mypy]
plugins = mypy_pure.plugin

Usage

Pure function (no side-effects):

from mypy_pure.decorators import pure

@pure
def add(x: int, y: int) -> int:
    return x + y

Impure function (with side-effects):

import os
from mypy_pure.decorators import pure

@pure
def bad() -> None:
    os.remove("file.txt")

Configuration

You can configure additional impure functions in your mypy.ini file:

[mypy-pure]
impure_functions = my_module.impure_func, another_module.bad_func

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

mypy_pure-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

mypy_pure-0.1.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file mypy_pure-0.1.0.tar.gz.

File metadata

  • Download URL: mypy_pure-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mypy_pure-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c7018f7701f8daccff626489c1e4fe06bab872893e895b52c8a607735aeb21b1
MD5 769d91584bebf7a12134d0b50a9aa994
BLAKE2b-256 43371dfcd4bdc265684e3189eff42b08bb8cc46bf702dc56adb47e57ec2143d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for mypy_pure-0.1.0.tar.gz:

Publisher: publish_on_pypi.yml on diegojromerolopez/mypy-pure

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

File details

Details for the file mypy_pure-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mypy_pure-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mypy_pure-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7900f20f852b913bdb9839dc9277241299873762f3f251d312fb08ef20fe138
MD5 e09f12cd5de932002875653235910eb1
BLAKE2b-256 369128afbcdc8af70681f32026c617a9cb018cf8d17829f5c4405b17a897e390

See more details on using hashes here.

Provenance

The following attestation bundles were made for mypy_pure-0.1.0-py3-none-any.whl:

Publisher: publish_on_pypi.yml on diegojromerolopez/mypy-pure

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