[Python-ideas] Statically checking purity of functions
Ed Minnix
egregius313 at gmail.com
Thu Jun 9 18:10:24 EDT 2016
Perhaps this would work better with something like property based testing of some sort. You would take a function and say for the allowed types, run a memoization series and check if the return value is the same every time for the arguments.
E.g., if you know the function can only take subclasses of numbers.Number whose arithmetic operators are pure, the type checker / test suite can verify.
Code such as:
>>> def add(a: int, b: int) -> int:
... return a + b
...
would allow for a test:
@given(integers(), integers())
def add_testing(a, b):
result_1 = add(a,b)
assert isinstance(result_1, int)
for _ in range(100):
assert result_1 == add(a,b)
- Ed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160609/4882b60a/attachment.html>
More information about the Python-ideas
mailing list