Cannot call dict.get with a falsy second argument and an 'or' expression.
オープン
まだ誰も着手していません。
bug
false-positive
priority-1-normal
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
In mypy 0.610, as well as the latest version from master, the following throws an error under Python 3.6
def foo(a: str):
pass
d = {'key': 'a'}
foo(d.get('key', None) or '26')
test.py:6: error: Argument 2 to "get" of "Mapping" has incompatible type "None"; expected "str"
However, no matter what, foo will still receive a str, given that None is falsy. Therefore, no error should be thrown. This occurs with just a simple call to mypy foo.py with no flags.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
test.py の最小再現から始め、Python 3.6 で mypy foo.py を実行してください。結果が示された or 式で使用される場合に、型チェッカーが Mapping.get をどのように扱うかを追跡してください。例で互換性のない None 引数が報告されなくなり、同様の呼び出しに対する適切な型チェックが維持されていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100