Skip to content

Commit 0c6ad49

Browse files
committed
Small refactorings
1 parent 45b6484 commit 0c6ad49

File tree

1 file changed

+20
-33
lines changed
  • hypothesis-python/src/hypothesis/internal/conjecture

1 file changed

+20
-33
lines changed

hypothesis-python/src/hypothesis/internal/conjecture/shrinker.py

+20-33
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ def __init__(self, engine, initial, predicate, allow_transition):
278278

279279
# We keep track of the current best example on the shrink_target
280280
# attribute.
281-
self.shrink_target = None
282-
self.update_shrink_target(initial)
281+
self.shrink_target = initial
282+
self.clear_change_tracking()
283283
self.shrinks = 0
284284

285285
# We terminate shrinks that seem to have reached their logical
@@ -447,23 +447,15 @@ def s(n):
447447
return "s" if n != 1 else ""
448448

449449
total_deleted = self.initial_size - len(self.shrink_target.buffer)
450-
451-
self.debug("---------------------")
452-
self.debug("Shrink pass profiling")
453-
self.debug("---------------------")
454-
self.debug("")
455450
calls = self.engine.call_count - self.initial_calls
451+
456452
self.debug(
457-
"Shrinking made a total of %d call%s "
458-
"of which %d shrank. This deleted %d byte%s out of %d."
459-
% (
460-
calls,
461-
s(calls),
462-
self.shrinks,
463-
total_deleted,
464-
s(total_deleted),
465-
self.initial_size,
466-
)
453+
"---------------------\n"
454+
"Shrink pass profiling\n"
455+
"---------------------\n\n"
456+
f"Shrinking made a total of {calls} call{s(calls)} of which "
457+
f"{self.shrinks} shrank. This deleted {total_deleted} bytes out "
458+
f"of {self.initial_size}."
467459
)
468460
for useful in [True, False]:
469461
self.debug("")
@@ -828,22 +820,17 @@ def __changed_blocks(self):
828820

829821
def update_shrink_target(self, new_target):
830822
assert isinstance(new_target, ConjectureResult)
831-
if self.shrink_target is not None:
832-
self.shrinks += 1
833-
# If we are just taking a long time to shrink we don't want to
834-
# trigger this heuristic, so whenever we shrink successfully
835-
# we give ourselves a bit of breathing room to make sure we
836-
# would find a shrink that took that long to find the next time.
837-
# The case where we're taking a long time but making steady
838-
# progress is handled by `finish_shrinking_deadline` in engine.py
839-
self.max_stall = max(
840-
self.max_stall, (self.calls - self.calls_at_last_shrink) * 2
841-
)
842-
self.calls_at_last_shrink = self.calls
843-
else:
844-
self.__all_changed_blocks = set()
845-
self.__last_checked_changed_at = new_target
846-
823+
self.shrinks += 1
824+
# If we are just taking a long time to shrink we don't want to
825+
# trigger this heuristic, so whenever we shrink successfully
826+
# we give ourselves a bit of breathing room to make sure we
827+
# would find a shrink that took that long to find the next time.
828+
# The case where we're taking a long time but making steady
829+
# progress is handled by `finish_shrinking_deadline` in engine.py
830+
self.max_stall = max(
831+
self.max_stall, (self.calls - self.calls_at_last_shrink) * 2
832+
)
833+
self.calls_at_last_shrink = self.calls
847834
self.shrink_target = new_target
848835
self.__derived_values = {}
849836

0 commit comments

Comments
 (0)