mr-proper

0.0.7 · active · verified Wed Apr 15

Mr-proper is a static Python code analyzer that aims to identify whether functions are 'pure' or not, and to explain the reasons behind its conclusions. It's a highly experimental library with known edge cases, and its definition of purity is specific to its implementation. The latest version is 0.0.7, released in October 2021, indicating an irregular release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mr-proper` programmatically by parsing an AST node (a function definition) and checking its purity using `is_function_pure`. It shows both a pure and a non-pure function example.

import ast
from mr_propper.utils import is_function_pure

# Example of a pure function
func_def_pure = ast.parse('''
def add_one(n: int) -> int:
    return n + 1
''').body[0]

is_pure, errors = is_function_pure(func_def_pure, with_errors=True)
print(f"'add_one' is pure: {is_pure}, Errors: {errors}")

# Example of a non-pure function
func_def_not_pure = ast.parse('''
def print_amount_of_users(users_qs: list) -> None:
    print(f'Current amount of users is {len(users_qs)}')
''').body[0]

is_pure, errors = is_function_pure(func_def_not_pure, with_errors=True)
print(f"'print_amount_of_users' is pure: {is_pure}, Errors: {errors}")

view raw JSON →