Static Python code analyzer, that tries to check if functions in code are pure or not and why.
Archived. The repository is read-only: no more fixes or releases will come.
$
pip install mr-propermr. Proper
Static Python code analyzer, that tries to check if functions in code are pure or not and why.

DISCLAIMER: this library is very experimental and has a lot of edge cases. Functions that mr. Proper marks as pure can be not pure, but they are usually cleaner than other functions.
Installation
pip install mr_proper
What mr. Proper check
- that function has no blacklisted calls (like
print) and blacklisted attributes access (likesmth.count); - that function not uses global objects (only local vars and function arguments);
- that function has al least one return;
- that function not mutates it's arguments;
- that function has no local imports;
- that function has no arguments of forbidden types (like ORM objects);
- that function not uses
self,classorsuper; - that function has calls of only pure functions.
This list is not enought to say that function is pure and some points are quite controversial, but it's a nice start.
Example
Console usage:
# test.py
def add_one(n: int) -> int:
return n + 1
def print_amount_of_users(users_qs: QuerySet) -> None:
print(f'Current amount of users is {users_qs.count()}')
$ mr_propper test.py
add_one is pure!
print_amount_of_users is not pure because of:
it uses forbidden argument types (QuerySet)
it calls not pure functions (print)
it has no return