false positive "name not defined" with list comprehension in function arguments default value
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
- Are you reporting a bug, or opening a feature request?
This is a bug I believe
- Please insert below the code you are checking with mypy
def a():
pass
def b(
bb=[list_comprehension_argument for list_comprehension_argument in "abc"
if list_comprehension_argument]
):
pass
- What is the actual behavior/output?
mypy repro.py
repro.py:5: error: Name 'list_comprehension_argument' is not defined
repro.py:6: error: Name 'list_comprehension_argument' is not defined
Found 2 errors in 1 file (checked 1 source file)
- What is the behavior/output you expect?
I believe there should be no error reported.
- What are the versions of mypy and Python you are using?
Do you see the same issue after installing mypy from Git master?
this is on mypy from git master, mypy 0.790+dev.2b704df25ca299e6936927be8d41d2ab945cee2a
- What are the mypy flags you are using? (For example --strict-optional)
This is using the default flags.
This only seem to happens if there's another function like this one, before the function with list comprehension in arguments:
def a():
pass
When removing this other function or putting it after the one with list comprehension in argument, this false positive is not reported, I mean no error are reported for:
def b(
bb=[list_comprehension_argument for list_comprehension_argument in "abc"
if list_comprehension_argument]
):
pass
def a():
pass
or
def b(
bb=[list_comprehension_argument for list_comprehension_argument in "abc"
if list_comprehension_argument]
):
pass
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
参照されている git-master バージョンで、示されている関数順序のバリエーションを使って mypy repro.py を実行し、報告を再現します。関数引数のデフォルト値とリスト内包表記のスコープの処理を追跡し、その後、両方の順序を対象とするリグレッションテストを追加します。誤検出による名前エラーが発生せず、既存のテストスイートが成功すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100