python / python/mypy

Cannot call dict.get with a falsy second argument and an 'or' expression.

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

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

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.

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

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

はじめの一歩

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

調査の方向性

test.py の最小再現から始め、Python 3.6 で mypy foo.py を実行してください。結果が示された or 式で使用される場合に、型チェッカーが Mapping.get をどのように扱うかを追跡してください。例で互換性のない None 引数が報告されなくなり、同様の呼び出しに対する適切な型チェックが維持されていれば完了です。

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

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

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

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