More flexible type support for `math.prod` and `math.sumprod`

未關閉
#13,501 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
48/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
python
領域
tooling

研究方向

先檢查 math.prod 和 math.sumprod 的型別存根,接著將它們的行為與 builtins.sum 的存根進行比較。使用連結的 Mypy Playground 範例檢查 Decimal、Fraction 和 complex 的推論,並在將該 issue 視為完成之前確認最終型別以及任何相容性方面的疑慮。

由索引模型根據 Issue 內容生成。

描述

stubs: improvement

Also related to https://github.com/python/typeshed/issues/11913

Currently, math.prod and math.sumprod do not properly support Decimal, Fraction, complex, or possibly other numeric types. This makes it inconvenient to replace builtins.sum with math.prod in a straightforward manner.

from typing import reveal_type
from fractions import Fraction
from math import prod

a = prod([Fraction(1), Fraction(2)])
reveal_type(a)  # it should be Fraction | Literal[1], but float for now

prod([complex(1, 0), complex(1, 2)])

Mypy Playground Link

I believe it should be followed the type stub of builtins.sum, but I’m not sure what breaking changes this might cause.

主要語言
Python
星號
5.1k
分支
2.1k
平均合併
2 天 4 小時
30 天內合併 PR
122

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python/typeshed 的其他 Issue

查看 python/typeshed 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。