NamedTuple with dependent default values causes unexpected 'Name is not defined' errors
オープン
まだ誰も着手していません。
false-positive
needs discussion
priority-1-normal
topic-named-tuple
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Hi there,
When there is a NamedTuple with a default value that depends on one or more other default values, followed by a default value that should resolve into a NameError, all preceding default values get the Name <variable> is not defined error as well.
E.g.
from typing import NamedTuple
class Example(NamedTuple):
a: int = 1
b: int = 2
c: int = a*b
d: int = does_not_exist*5
Causes:
scratch.py:6: error: Name 'a' is not defined
scratch.py:6: error: Name 'b' is not defined
scratch.py:7: error: Name 'does_not_exist' is not defined
If I comment out line 6, I do, however, get the expected result.
from typing import NamedTuple
class Example(NamedTuple):
a: int = 1
b: int = 2
# c: int = a*b
d: int = does_not_exist*5
scratch.py:7: error: Name 'does_not_exist' is not defined
This was tried on version 0.760.
$ mypy --version
mypy 0.760
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、mypy 0.760を使ってscratch.pyのNamedTupleの例から問題を再現し、次にデフォルト値を担当するNamedTupleの型チェック経路を調べます。依存するデフォルト値のケースと、cをコメントアウトしたバージョンを比較します。d内の未定義の名前が、a、b、cに対する余計なエラーなしに報告されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100