python / python/mypy

Parameters for a call to a function wrapped in a lru_cache are not checked

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

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

bug
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

Bug Report

The parameters used in a call to a function which is wrapped in a functools.lru_cache are not checked.

To Reproduce

from datetime import date
from functools import lru_cache

@lru_cache
def f(v: str, at: date) -> str:
    return v

f()
f("abc")
f("abc", date.today())
f("abc", now=date.today())
f("abc", at=date.today())
f("abc", at="wrong_type")

Expected Behavior

This should raise several errors about the arguments being wrong. Commenting out the line @lru_cache correctly generates the following errors.

lru_cache_type_test.py:8: error: Missing positional arguments "v", "at" in call to "f"  [call-arg]
lru_cache_type_test.py:9: error: Missing positional argument "at" in call to "f"  [call-arg]
lru_cache_type_test.py:11: error: Unexpected keyword argument "now" for "f"  [call-arg]
lru_cache_type_test.py:13: error: Argument "at" to "f" has incompatible type "str"; expected "date"  [arg-type]

Actual Behavior

Success: no issues found in 1 source file

Your Environment

mypy 1.6.0 running on Python 3.11.6

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

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

はじめの一歩

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

調査の方向性

lru_cache_type_test.py に記載されている reproducer から始め、@lru_cache ありとなしで mypy を実行して違いを確認します。functools.lru_cache でラップされた関数がどのように解析されるかを追跡し、引数の不足、予期しないキーワード、互換性のない型についてのカバレッジを追加します。これらの呼び出しで期待されるエラーが報告され、有効な呼び出しが引き続き受け入れられれば完了です。

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

評価

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

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

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