Incompatible typing for `logging.Formatter.converter` and `time.gmtime`/`time/localtime` ?
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
從參照的定義開始檢查 stdlib/logging/init.pyi 和 stdlib/time.pyi,然後使用 issue 中的範例透過 mypy 重現指派。檢查為什麼兩個可呼叫註解會被視為不相容,並更新相關的 stub 型別標註,讓該範例能在沒有指派錯誤的情況下通過型別檢查。
由索引模型根據 Issue 內容生成。
描述
The typing for converter here is as follows:
converter: Callable[[float | None], struct_time]
And the typing for time.gmtime/time.localtime here is:
def gmtime(seconds: float | None = None, /) -> struct_time: ...
def localtime(seconds: float | None = None, /) -> struct_time: ...
Yet when I try to typecheck this code:
import logging
import time
class UTCFormatter(logging.Formatter):
converter = time.gmtime
I get the following error:
$ mypy main.py
main.py:5: error: Incompatible types in assignment (expression has type "Callable[[], struct_time]", base class "Formatter" defined the type as "Callable[[float | None], struct_time]") [assignment]
Found 1 error in 1 file (checked 1 source file)
I tested this on a fresh python3.13 venv with the following deps installed:
mypy==1.18.2
mypy_extensions==1.1.0
pathspec==0.12.1
typing_extensions==4.15.0
- 主要語言
- Python
- 星號
- 5.1k
- 分支
- 2.1k
- 平均合併
- 2 天 7 分鐘
- 30 天內合併 PR
- 116
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/typeshed 的其他 Issue
-
`networkx.set_edge_attributes` should support scalar value + name可能已有人在做 @Fire162 於 9 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 67/100
維護者通常 1 天內回覆
-
false alarm on decode call可能已有人在做 @jw9829 於 37 天前認領。 未關閉help wanted stubs: false positive
難度 2/5 1-3 小時 新手友好度 76/100
python/typeshed#16441 · 1 則留言 ·
維護者通常 1 天內回覆
-
Don't run pyright basic checks on projects with strict pyright settings in CI可能已有人在做 @Mohith1612 於 73 天前認領。 未關閉project: infrastructure
難度 2/5 1-3 小時 新手友好度 68/100
python/typeshed#16005 · 1 則留言 ·
維護者通常 1 天內回覆
-
stubs: improvement
難度 2/5 1-3 小時 新手友好度 72/100
python/typeshed#15548 · 5 則留言 ·
維護者通常 1 天內回覆
-
stubs: improvement
難度 2/5 1-3 小時 新手友好度 64/100
python/typeshed#15529 · 5 則留言 ·
維護者通常 1 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 62/100
earthtojake/text-to-cad#758 ·
維護者通常 1 天內回覆
-
domain:upgrades enhancement needs-triage
難度 2/5 1-3 小時 新手友好度 66/100
gke-labs/kube-agents#4634 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
agardnerIT/opamp-server-py#116 ·
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
enhancement good first issue
難度 2/5 1-3 小時 新手友好度 78/100
elviskahoro/sdk-python-attio#144 · 1 則留言 ·
維護者通常 1 天內回覆