Lambda as RHS for operator always gets inferred as Any
オープン
まだ誰も着手していません。
bug
priority-2-low
topic-disallow-any
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
説明
When a lambda is given as the RHS in an operator (example uses >>, but also occurs with others), the lambda’s type is always inferred as Any. Whereas calling the operator function directly, or passing an explicit function, does not.
from typing import Callable, Generic, TypeVar
_T = TypeVar('_T')
_U = TypeVar('_U')
class A(Generic[_T]):
_value: _T
def __init__(self, val: _T) -> None: ...
def __rshift__(self, f: Callable[[_T], _U]) -> _U: ...
def inc(x: int) -> int: ...
A(1) >> inc # No error
A(1).__rshift__(lambda x: x + 1) # No error
A(1) >> (lambda x: x + 1)
# │ └ Expression has type "Any"
# └ Expression type contains "Any" (has type Callable[[Any], Any])
- Python 3.7.0
- mypy 0.641
- mypy config:
[mypy] check_untyped_defs = True disallow_any_decorated = True disallow_any_expr = True disallow_any_unimported = True disallow_incomplete_defs = True disallow_subclassing_any = True disallow_untyped_calls = True disallow_untyped_decorators = True disallow_untyped_defs = True warn_return_any = True warn_unused_ignores = True
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された Python の再現コードを、記載された mypy 設定で実行し、演算子形式を直接のメソッド呼び出しおよび名前付き関数と比較します。そのエントリポイントから演算子式の型推論を追跡します。完了条件は、括弧で囲まれた lambda が Any を生成するのではなく、オペランドの型から推論されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100