Skip to content

bpo-42944 Fix Random.sample when counts is not None #24235

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

Merged
merged 5 commits into from
Jan 18, 2021

Conversation

jonanifranco
Copy link
Contributor

@jonanifranco jonanifranco commented Jan 17, 2021

Use the instance generator instead of the module generator.

https://bugs.python.org/issue42944

Replace [Random.]sample by self.sample in Random.sample path when count is not None to correctly use instance generator instead of module generator.
@the-knights-who-say-ni
Copy link

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 Missing

Our records indicate the following people have not signed the CLA:

@jonanifranco

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
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@rhettinger
Copy link
Contributor

  • Please sign the contributor agreement (CLA).
  • Add a test that fails before the PR and passes afterward.
  • Add a Misc/NEWS entry using Blurb.

@rhettinger rhettinger added the needs backport to 3.9 only security fixes label Jan 17, 2021
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

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.

@jonanifranco
Copy link
Contributor Author

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
@rhettinger
Copy link
Contributor

Please add an entry to Misc/NEWS.

@jonanifranco
Copy link
Contributor Author

Please add an entry to Misc/NEWS.

Done.
I also signed the CLA yesterday.

@rhettinger rhettinger merged commit f7b5bac into python:master Jan 18, 2021
@miss-islington
Copy link
Contributor

Thanks @jonanifranco for the PR, and @rhettinger for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 18, 2021
@bedevere-bot
Copy link

GH-24243 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Jan 18, 2021
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
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.

7 participants