Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add require_also and ensure_also arguments #45

Open
mristin opened this issue Jun 3, 2021 · 0 comments
Open

Add require_also and ensure_also arguments #45

mristin opened this issue Jun 3, 2021 · 0 comments

Comments

@mristin
Copy link
Owner

mristin commented Jun 3, 2021

Currently, the developer has to write a "more restricted" version of the function if large values for one or more arguments result in impractical computation times.

For example, ETHZ Eprog 2019 Ex. 8 Prob. 3:

@require(lambda steps: 0 <= steps < 100)
def restricted_simulate(
	specs: problem_03.Specs, steps: int
) -> problem_03.Stats:
	return problem_03.simulate(specs, steps)

for func in [restricted_simulate]:
	try:
		icontract_hypothesis.test_with_inferred_strategy(func)
	except Exception as error:
		....

This is unnecessarily verbose and often error-prone (e.g., all the pre-conditions of the original function need to be repeated).

Instead, it would be great if we could just write something like:

icontract_hypothesis.test_with_inferred_strategy(
    problem_03.simulate, 
    require_also=[lambda steps: steps < 100]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant