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:
- Deterministic: Its return value is the same for the same arguments.
- 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7018f7701f8daccff626489c1e4fe06bab872893e895b52c8a607735aeb21b1
|
|
| MD5 |
769d91584bebf7a12134d0b50a9aa994
|
|
| BLAKE2b-256 |
43371dfcd4bdc265684e3189eff42b08bb8cc46bf702dc56adb47e57ec2143d8
|
Provenance
The following attestation bundles were made for mypy_pure-0.1.0.tar.gz:
Publisher:
publish_on_pypi.yml on diegojromerolopez/mypy-pure
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mypy_pure-0.1.0.tar.gz -
Subject digest:
c7018f7701f8daccff626489c1e4fe06bab872893e895b52c8a607735aeb21b1 - Sigstore transparency entry: 731735910
- Sigstore integration time:
-
Permalink:
diegojromerolopez/mypy-pure@3c3e789a2d612105ff0a843edc261bc56d09bcf3 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/diegojromerolopez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_on_pypi.yml@3c3e789a2d612105ff0a843edc261bc56d09bcf3 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7900f20f852b913bdb9839dc9277241299873762f3f251d312fb08ef20fe138
|
|
| MD5 |
e09f12cd5de932002875653235910eb1
|
|
| BLAKE2b-256 |
369128afbcdc8af70681f32026c617a9cb018cf8d17829f5c4405b17a897e390
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mypy_pure-0.1.0-py3-none-any.whl -
Subject digest:
e7900f20f852b913bdb9839dc9277241299873762f3f251d312fb08ef20fe138 - Sigstore transparency entry: 731735915
- Sigstore integration time:
-
Permalink:
diegojromerolopez/mypy-pure@3c3e789a2d612105ff0a843edc261bc56d09bcf3 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/diegojromerolopez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_on_pypi.yml@3c3e789a2d612105ff0a843edc261bc56d09bcf3 -
Trigger Event:
release
-
Statement type: