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

Hook for managing any Random instance #1741

Merged
merged 1 commit into from
Jan 22, 2019
Merged

Conversation

Zac-HD
Copy link
Member

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

This generalises our management of the global random and numpy.random states to work for any registered Random instance. That's useful for simulation and scheduling frameworks that maintain their own random state, such as Trio.

Closes #1709, related to python-trio/trio#239 and python-trio/pytest-trio#73

@Zac-HD Zac-HD added the enhancement it's not broken, but we want it to be better label Jan 6, 2019
@Zac-HD Zac-HD force-pushed the any-prng branch 2 times, most recently from ccaf274 to 6144fdb Compare January 6, 2019 04:33
@Zac-HD
Copy link
Member Author

Zac-HD commented Jan 17, 2019

Ping @HypothesisWorks/hypothesis-python-contributors for review - I finally got all the tests passing at once!

If this API looks OK, I'd love to get it merged soon for the benefit of pytest-trio 😄

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.

The implementation looks fine, but I think the API needs maybe a bit more thought.

  • I'm not wild about random_module.register as the thing you need to call. It's both a strange API and also fairly non-obvious in that the things you pass to it don't logically have much to do with the random_module strategy. I think a top-level function like register_random or something like that would make more sense.
  • The fact that the function checks that the value of type Random is weird given that we are putting things in it that are not Random instances ourselves - this seems like a general use case. I would rather we use duck typing and document the interface we require.

@Zac-HD
Copy link
Member Author

Zac-HD commented Jan 22, 2019

@DRMacIver - done 😄

@Zac-HD Zac-HD merged commit 503a3ed into HypothesisWorks:master Jan 22, 2019
@Zac-HD Zac-HD deleted the any-prng branch January 22, 2019 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement it's not broken, but we want it to be better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants