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 booleans() and just() as sampled_from() for better collections #2122

Merged
merged 1 commit into from Oct 9, 2019

Conversation

Zac-HD
Copy link
Member

@Zac-HD Zac-HD commented Oct 6, 2019

Since #2031, we have some fancy handling for generating unique collections from some small known sequence of elements, i.e. UniqueSampledListStrategy and the related filtering improvements.

Now we take advantage of that logic for the common case that a strategy can only generate one (or perhaps two) elements. It's only a little more efficient on a per-case basis, but I was prompted by a FilteringTooMuch while mucking around so here it is.

@Zac-HD Zac-HD added the performance go faster! use less memory! label Oct 6, 2019
@Zac-HD Zac-HD force-pushed the small-samples branch 2 times, most recently from 64a8766 to f063f47 Compare October 9, 2019 12:37
return self.elements[0]

def __repr__(self):
return "just(%r)" % (value,)
Copy link
Member

Choose a reason for hiding this comment

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

self.value here?

(The build will tell you this anyway, but just to preempt it!)

Copy link
Member

@DRMacIver DRMacIver left a comment

Choose a reason for hiding this comment

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

Other the one issue that is (hopefully) failing the build, LGTM. Don't need to rereview when that's fixed.

While kinda weird on the face of it, this makes generating unique collections a *lot* more efficient in certain unusual cases, and the overhead is roughly nil.
@Zac-HD Zac-HD merged commit 8de5042 into HypothesisWorks:master Oct 9, 2019
@Zac-HD Zac-HD deleted the small-samples branch October 9, 2019 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance go faster! use less memory!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants