mypy reports `used-before-def` with `TypeAlias`es despite `from __future__ import annotations`
オープン
@ilinum がすでに取り組んでいます。
2023年1月27日 から。
bug
topic-possibly-undefined
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
from __future__ import annotations helps avoid NameErrors with later-defined entities in python, but seems to ineffective with use(d)-before-def in mypy.
To Reproduce (edited example code, see edit history for previous version if I mis-edited anything):
"""Bug."""
from __future__ import annotations
from typing import TYPE_CHECKING
# This works (only) with `from __future__ import annotations`:
list_direct: list[Class] = []
# By contrast, mypy reports `used-before-def` either way:
if TYPE_CHECKING:
ListOfClass = list[Class]
list_via_alias: ListOfClass = []
class Class:
pass
Expected Behavior
No error
Actual Behavior
bug.py:8: error: Name "MyClass" is used before definition [used-before-def]
Your Environment
- Mypy version used: mypy 1.0.0+dev.425fb0b4cfaa78cd0bf23fd165e4d6a1170670fe (compiled: no)
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.11.1
Related: https://github.com/python/mypy/pull/14163, https://github.com/python/mypy/pull/14166
Interestingly, no error on playground on master:
https://mypy-play.net/?mypy=master&python=3.11&gist=f323516535c0d04cf4e0a2f2c985f4ff
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
評価
この issue はまだ評価されていません。