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

Implement NodeTemplate + small fixes #4173

Merged
merged 7 commits into from
Nov 15, 2024
Merged

Conversation

tybug
Copy link
Member

@tybug tybug commented Nov 14, 2024

Split from #4172. Recommend reviewing by commit.

Comment on lines +152 to 156
start_idx = len(self.data.ir_nodes)
with deprecate_random_in_strategy("from {}={!r}", k, s) as check:
obj = check(self.data.draw(s, observe_as=f"generate:{k}"))
end_idx = self.data.index_ir
end_idx = len(self.data.ir_nodes)
kwargs[k] = obj
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is because index_ir has diverged a bit from the buffer concept of "index into the choice sequence". Rather than try to sync a separate variable with that concept like we did with .index for buffers, I think the very few usage sites can just use the more verbose len(nodes).

@tybug
Copy link
Member Author

tybug commented Nov 14, 2024

hypothesis-python/tests/conjecture/test_ir.py:1043:39: RUF005 Consider (*ir(1), NodeTemplate("simplest", size=5)) instead of concatenation
|
1042 | def test_node_template_to_overrun():
1043 | data = ConjectureData.for_ir_tree(ir(1) + (NodeTemplate("simplest", size=5),))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF005
1044 | data.draw_integer()
1045 | with pytest.raises(StopTest):
|
= help: Replace with (*ir(1), NodeTemplate("simplest", size=5))

I think the suggestion reads worse, thoughts on disabling this lint rule?

Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See notes, but this looks good overall 🙂

if size + self.length_ir > self.max_length_ir:
if self.length_ir + size > self.max_length_ir:
debug_report(
f"overrun because {self.length_ir} + {size} > {self.max_length_ir=}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f"overrun because {self.length_ir} + {size} > {self.max_length_ir=}"
f"overrun because {self.length_ir=} + {size=} > {self.max_length_ir=}"

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was semi intentional, but yeah I think with = is fine.

hypothesis-python/tests/conjecture/common.py Outdated Show resolved Hide resolved
hypothesis-python/tests/conjecture/common.py Outdated Show resolved Hide resolved
Comment on lines +814 to +815
# we don't consider shrink_towards for unbounded integers.
# the trivial value should probably be 1 here, not 0.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure we should change this, though maybe in a follow-up PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree - I was hoping to hold off until ordering is on the ir though, where this will be simpler to implement. If nobody has noticed yet then it should be ok for another month?

@tybug tybug merged commit afc133e into HypothesisWorks:master Nov 15, 2024
49 checks passed
@tybug tybug deleted the node-template branch November 15, 2024 03:12
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

Successfully merging this pull request may close these issues.

2 participants