Incompatible typing for `logging.Formatter.converter` and `time.gmtime`/`time/localtime` ?
オープン
まだ誰も着手していません。
stubs: false positive
- 主要言語
- Python
- スター
- 5.1k
- フォーク
- 2.1k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 82
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
参照されている定義の stdlib/logging/init.pyi と stdlib/time.pyi から始め、issue の例を使って mypy で代入を再現します。2 つの callable アノテーションが互換性のないものとして扱われる理由を確認し、代入エラーなしで例の型チェックが通るように、該当する stub の型付けを更新します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 50/100