-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhelpers.py
More file actions
31 lines (24 loc) · 796 Bytes
/
helpers.py
File metadata and controls
31 lines (24 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import annotations
import typing
import astroid
from deal_solver import Contract, Proof, Theorem
from deal_solver._ast import get_name
class TestTheorem(Theorem):
@staticmethod
def get_contracts(func: astroid.FunctionDef) -> typing.Iterator[Contract]:
if not func.decorators:
return
for contract in func.decorators.nodes:
name = get_name(contract.func)
assert name
yield Contract(
name=name.split('.')[-1],
args=contract.args,
)
def prove_f(text: str, **kwargs) -> Proof:
theorems = list(TestTheorem.from_text(text, **kwargs))
theorem = theorems[-1]
assert theorem.name == 'f'
proof = theorem.prove()
print(repr(proof))
return proof