bpo-42944 Fix Random.sample when counts is not None#24235
bpo-42944 Fix Random.sample when counts is not None#24235rhettinger merged 5 commits intopython:masterfrom
Conversation
Replace [Random.]sample by self.sample in Random.sample path when count is not None to correctly use instance generator instead of module generator.
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
|
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Interesting, that there is a test which should catch this bug, but it does not work because it tests only global random.sample().
Please replace random with self.gen in test_sample_counts_equivalence and move that method to MersenneTwister_TestBasicOps, because it does not make sense for SystemRandom.
|
I had just updated my master branch with a new test before reading @serhiy-storchaka comment. I update again test_random.py as suggested. |
test_sample_counts_equivalence should catch bpo-42944, but it does not work because it tests only global random.sample. random is replaced by self.gen in test_sample_counts_equivalence and that method is moved to MersenneTwister_TestBasicOps, because it does not make sense for SystemRandom
|
Please add an entry to Misc/NEWS. |
Done. |
Misc/NEWS.d/next/Library/2021-01-18-10-41-44.bpo-42944.RrONvy.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Ken Jin <[email protected]>
|
Thanks @jonanifranco for the PR, and @rhettinger for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
(cherry picked from commit f7b5bac) Co-authored-by: jonanifranco <[email protected]>
|
GH-24243 is a backport of this pull request to the 3.9 branch. |
Use the instance generator instead of the module generator.
https://bugs.python.org/issue42944