-
Notifications
You must be signed in to change notification settings - Fork 594
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
Improve pprinting of stateful examples #4266
Open
tybug
wants to merge
1
commit into
HypothesisWorks:master
Choose a base branch
from
tybug:stateful-pprint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
RELEASE_TYPE: patch | ||
|
||
Improve the clarity of printing counterexamples in :doc:`stateful testing <stateful>`, by avoiding confusing :class:`~hypothesis.stateful.Bundle` references with equivalent values drawn from a regular strategy. | ||
|
||
For example, we now print: | ||
|
||
.. code-block: python | ||
|
||
a_0 = state.add_to_bundle(a=0) | ||
state.unrelated(value=0) | ||
|
||
instead of | ||
|
||
.. code-block: python | ||
|
||
a_0 = state.add_to_bundle(a=0) | ||
state.unrelated(value=a_0) | ||
|
||
if the ``unrelated`` rule draws from a regular strategy such as :func:`~hypothesis.strategies.integers` instead of the ``a`` bundle. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here we actually do want
because e.g. lists are mutable and so it's valuable to show the variable name which communicates the identity of the value.
I realize that this is Quite A Can Of Worms, what with not wanting
values_0 = state.f(value=values_0)
; your motivating case in the changelog is spot-on but here and in the changed test I think the change is probably for the worse :/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree that this case is worse than it used to be, but it's also not a correct transformation to make in general; see
SourceSameAsTargetUnclearOrigin
, where we would getstate.f(value=[values_0])
even if the inner empty list came fromst.just([])
. And one could imagine more complicated cases of building up the inner list via some alternative st.composite where this would be more misleading.I think we have to decide which of the two evils is worse...I believe the only case worsened by this is strategies involving bundles, which isn't great but is less common than rules involving bundles. The latter case collides relatively frequently thanks to shrinking normalizing to e.g. lots of zeros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we did
self.__printer.singleton_pprinters.setdefault(id(result), printer)
, but only for objects which are not actually singletons? i.e. excluding None, True, False, small integers; we're still going to miss some cases but it seems closer to a strict improvement on the status quo.