mr-proper
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
- gotcha The library is explicitly stated as 'very experimental and has a lot of edge cases'. Functions marked as pure might not be strictly pure by other definitions, though they are generally cleaner. Rely on its findings with caution.
- breaking The PyPI package name is `mr-proper` (with a hyphen), but the import statement requires `mr_propper` (with an underscore and a double 'p'). Using `import mr_proper` will result in an `ImportError`.
- gotcha The command-line interface (CLI) for `mr-proper` currently does not support checking directories recursively; it only accepts individual Python file paths.
- gotcha The project's activity has been low, with the last release in October 2021. This might imply slower responses to issues, potential unaddressed bugs, or a lack of new features.
Install
-
pip install mr-proper
Imports
- is_function_pure
from mr_proper.utils import is_function_pure
from mr_propper.utils import is_function_pure
Quickstart
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}")