(🐞) `type.__call__` not checked properly
オープン
まだ誰も着手していません。
bug
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
class A:
def __init__(self, x: int):
print(x)
A.__call__("a") # no error
A("a") # Argument 1 to "A" has incompatible type "str"; expected "int" [arg-type]
The typing spec says:
At runtime, a call to a class’ constructor typically results in the invocation of three methods in the following order:
- The
__call__method of the metaclass (which is typically supplied by thetypeclass but can be overridden by a custom metaclass and which is responsible for calling the next two methods)
So mypy is checking that usages of the call syntax (()) are conforming to the constructor type, but the functionally identical call attribute __call__. This is against the spec, which specifies that type checkers should mirror the behavior that __call__ will invoke __new__ and __init__
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、コンストラクター呼び出しと type.__call__ への属性呼び出しに対する mypy の処理を、issue の例を再現ケースとして使って調べます。A("a") と A.__call__("a") がそれぞれどのようにチェックされるかを追跡し、両方の形式でコンストラクター引数の型が強制されることを示すカバレッジを追加します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100