python / python/cpython

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

Đang mở
#135,378 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

pending stdlib type-feature
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tìm các phần triển khai và các bài kiểm thử cho Random.getrandbits(), SystemRandom.getrandbits(), Random.randbytes(), SystemRandom.randbytes(), sample() và binomialvariate(). So sánh cách chúng xử lý các đối số không phải số nguyên, sau đó xác minh rằng các đối số được hỗ trợ luôn sử dụng index() một cách nhất quán và các đầu vào không hợp lệ của binomialvariate() bị từ chối.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
backend
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.