Skip to content

Support __index__() in getrandbits(), randbytes() and others #135378

Open
1 of 1 issue completed
Open
@serhiy-storchaka

Description

@serhiy-storchaka

Feature or enhancement

Support of the __index__() method in getrandbits() and randbytes() is inconsistent.

  • Random.getrandbits() supports __index__(), but SystemRandom.getrandbits() does not.
  • SystemRandom.randbytes() supports __index__(), but Random.randbytes() does not.

For consistence, both classes should support it.

sample() fails if its k argument is not integer. k should have __index__(), but it also should support comparison with integers and multiplication by list and integer. It is easy to make it more general, and only require __index__(). It will also produce more meaningful error.

binomialvariate() seems "working" with non-integer n argument, but the result is questionable. Passing non-integer value is most likely an error, and it would be better to detect it.

cc @rhettinger

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.15new features, bugs and security fixesstdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions