Skip to content

Add missing randbytes method on random - #3209

Merged
youknowone merged 3 commits into
RustPython:mainfrom
osman-turan:main
Oct 6, 2021
Merged

youknowone merged 3 commits into
RustPython:mainfrom
osman-turan:main

Conversation

@osman-turan

Copy link
Copy Markdown
Contributor

This PR adds missing randbytes method on random (see official documentation for the method: https://docs.python.org/3/library/random.html#random.randbytes).

@fanninpm

fanninpm commented Oct 3, 2021

Copy link
Copy Markdown
Contributor

Heads up: Currently our GitHub Actions workflow uses CPython 3.8 as a reference. You might want to add something to extra_tests/snippets if that step complains about a method that's from a newer version.

@osman-turan

Copy link
Copy Markdown
Contributor Author

Thanks @fanninpm! It was my first PR, I didn't know that. I added some tests with 6fc278f.

@youknowone

Copy link
Copy Markdown
Member

#2831

Comment on lines +26 to +33
# random.randbytes
random.seed(1234)
zero_size_buf = random.randbytes(0)
assert type(zero_size_buf) is bytes
assert len(zero_size_buf) == 0
non_zero_buf = random.randbytes(4)
assert type(non_zero_buf) is bytes
assert list(non_zero_buf) == list(b'\xb9\x7fi\xf7')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Try experimenting with testutils.skip_if_unsupported (defined here). Here's an example of it in action.

@fanninpm

fanninpm commented Oct 5, 2021

Copy link
Copy Markdown
Contributor

Actually, with #2831 having been merged, the points I have raised up to now are no longer applicable.

@youknowone can we rerun the CI for this PR?

@osman-turan

Copy link
Copy Markdown
Contributor Author

Thanks, @fanninpm for the hints! Sorry for the late reply. If you need any other modifications, please let me know. I'll be happy to apply your suggestions.

@youknowone

Copy link
Copy Markdown
Member

could you rebase it to run tests with python3.9?

@osman-turan

Copy link
Copy Markdown
Contributor Author

@youknowone Done 👍

@youknowone
youknowone merged commit d49ab19 into RustPython:main Oct 6, 2021
@youknowone

Copy link
Copy Markdown
Member

thank you for contributing!

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.

3 participants