Support __index__() in getrandbits(), randbytes() and others
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Feature or enhancement
Support of the __index__() method in getrandbits() and randbytes() is inconsistent.
Random.getrandbits()supports__index__(), butSystemRandom.getrandbits()does not.SystemRandom.randbytes()supports__index__(), butRandom.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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
找出 Random.getrandbits()、SystemRandom.getrandbits()、Random.randbytes()、SystemRandom.randbytes()、sample() 和 binomialvariate() 的實作與測試。比較它們對非整數引數的處理方式,接著確認受支援的引數一致使用 index(),並拒絕無效的 binomialvariate() 輸入。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100