python / python/cpython

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

オープン
#135,378 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

pending stdlib type-feature
主要言語
Python
スター
77.2k
フォーク
36k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Random.getrandbits()、SystemRandom.getrandbits()、Random.randbytes()、SystemRandom.randbytes()、sample()、binomialvariate() の実装とテストを見つけてください。整数でない引数の扱いを比較し、そのうえで、サポートされている引数が一貫して index() を使用し、binomialvariate() の無効な入力が拒否されることを確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。