Mypy doesn't object to `cached_property` methods that don't exist
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
Mypy includes functools.cached_property on it's list of property-list types, but considers it to be too identical to property. It allows the use of cached_property.setter and cached_property.deleter without raising an error, despite the fact that neither of these are methods that exist on cached_property.
I discovered this while looking at permutations of property-like behavior for https://github.com/python/typeshed/pull/13276.
Actually, I realized just now that it can be anything from any of the property types. See the second playground link. [Edit: this part fixed by #19313]
To Reproduce
Playground link showing : https://mypy-play.net/?mypy=latest&python=3.12&gist=f5336c7a8df8f028a565bab576b74062
This one shows that mypy doesn't object to non-existent methods of property used as a decorator:
https://mypy-play.net/?mypy=latest&python=3.12&gist=d91764177a604ba5640a1fe741718f52 [Edit: this part fixed by #19313]
Expected Behavior
I expect mypy to generate errors for methods that don't exist in the stubs, even with the special-cased behavior.
Actual Behavior
No errors are generated.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンク先の mypy playground で Python 3.12 を使って動作を再現します。次に、property に似た型に対する mypy の特別扱いを調べ、cached_property が setter と deleter を受け入れる理由に焦点を当てます。cached_property に存在しないメソッドについて mypy がエラーを報告しつつ、cached_property の有効な動作が維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100