Skip to content

Commit c007798

Browse files
committed
add node.index
1 parent 3fded25 commit c007798

File tree

1 file changed

+9
-1
lines changed
  • hypothesis-python/src/hypothesis/internal/conjecture

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,11 @@ def freeze(self) -> None:
470470
def record_ir_draw(self, ir_type, value, *, kwargs, was_forced):
471471
self.trail.append(IR_NODE_RECORD)
472472
node = IRNode(
473-
ir_type=ir_type, value=value, kwargs=kwargs, was_forced=was_forced
473+
ir_type=ir_type,
474+
value=value,
475+
kwargs=kwargs,
476+
was_forced=was_forced,
477+
index=len(self.ir_nodes),
474478
)
475479
self.ir_nodes.append(node)
476480

@@ -955,11 +959,15 @@ class IRNode:
955959
value: IRType = attr.ib()
956960
kwargs: IRKWargsType = attr.ib()
957961
was_forced: bool = attr.ib()
962+
index: Optional[int] = attr.ib(default=None)
958963

959964
def copy(self, *, with_value: IRType) -> "IRNode":
960965
# we may want to allow this combination in the future, but for now it's
961966
# a footgun.
962967
assert not self.was_forced, "modifying a forced node doesn't make sense"
968+
# explicitly not copying index. node indices are only assigned via
969+
# ExampleRecord. This prevents footguns with relying on stale indices
970+
# after copying.
963971
return IRNode(
964972
ir_type=self.ir_type,
965973
value=with_value,

0 commit comments

Comments
 (0)