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

Python: Make top level random() raise #1952

Merged
merged 1 commit into from
Apr 22, 2024
Merged

Conversation

hoodmane
Copy link
Contributor

@hoodmane hoodmane commented Apr 3, 2024

We don't have access to entropy outside of request scope, so random() will give poor results. Raise an error if it is called.

@hoodmane hoodmane requested review from a team as code owners April 3, 2024 15:59
@hoodmane hoodmane changed the title Make top level random() raise Python: Make top level random() raise Apr 3, 2024
@hoodmane hoodmane force-pushed the hoodmane/no-toplevel-random branch from a458ad2 to 511e04f Compare April 3, 2024 16:01
Copy link
Collaborator

@dom96 dom96 left a comment

Choose a reason for hiding this comment

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

Just a few suggestions to make the code easier to understand, otherwise LGTM.

src/pyodide/internal/patches/random.py Outdated Show resolved Hide resolved
src/pyodide/internal/patches/random.py Outdated Show resolved Hide resolved
src/pyodide/internal/python.js Outdated Show resolved Hide resolved
@hoodmane hoodmane force-pushed the hoodmane/no-toplevel-random branch 4 times, most recently from 65f768a to 89f6af5 Compare April 9, 2024 14:00
@hoodmane
Copy link
Contributor Author

hoodmane commented Apr 9, 2024

Okay I updated this to handle numpy, added more detailed comments and internal tests.

@hoodmane hoodmane force-pushed the hoodmane/no-toplevel-random branch 2 times, most recently from fef5054 to 0f06a50 Compare April 9, 2024 18:21
@hoodmane
Copy link
Contributor Author

@jasnell jasnell added the python Issues/PRs relating to Python Workers label Apr 10, 2024
@hoodmane hoodmane force-pushed the hoodmane/no-toplevel-random branch 11 times, most recently from 698262d to 2fe472c Compare April 17, 2024 18:21
We don't have access to entropy outside of request scope, so `random()` will
give poor results. Raise an error if it is called.
@hoodmane hoodmane force-pushed the hoodmane/no-toplevel-random branch from 2fe472c to aa190bf Compare April 18, 2024 09:29
@hoodmane hoodmane merged commit 35f34fe into main Apr 22, 2024
10 checks passed
garrettgu10 pushed a commit that referenced this pull request May 13, 2024
We don't have access to entropy outside of request scope, so `random()` will
give poor results. Raise an error if it is called.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Issues/PRs relating to Python Workers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants