Skip to content

Commit

Permalink
improve minimal readability with nonlocal
Browse files Browse the repository at this point in the history
  • Loading branch information
tybug committed Jan 10, 2024
1 parent ba90e9e commit f6b7349
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions hypothesis-python/tests/common/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ class Timeout(BaseException):


def minimal(definition, condition=lambda x: True, settings=None, timeout_after=10):
definition.validate()
runtime = None
result = None

def wrapped_condition(x):
nonlocal runtime
if timeout_after is not None:
if runtime:
runtime[0] += TIME_INCREMENT
if runtime[0] >= timeout_after:
runtime += TIME_INCREMENT
if runtime >= timeout_after:
raise Timeout
result = condition(x)
if result and not runtime:
runtime.append(0.0)
runtime = 0.0
return result

if settings is None:
Expand All @@ -51,16 +56,14 @@ def wrapped_condition(x):
)
def inner(x):
if wrapped_condition(x):
result[:] = [x]
nonlocal result
result = x
raise Found

definition.validate()
runtime = []
result = []
try:
inner()
except Found:
return result[0]
return result
raise Unsatisfiable(
"Could not find any examples from %r that satisfied %s"
% (definition, get_pretty_function_description(condition))
Expand Down

0 comments on commit f6b7349

Please sign in to comment.