`NoReturn` on `__new__` and `__init__` disables accessing `@classmethod`s and `ClassVar`s directly from the class
オープン
まだ誰も着手していません。
bug
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
説明
Bug Report
Annotating __new__(...) -> typing.NoReturn or __init__(...) -> typing.NoReturn causes false positives when accessing @classmethods and typing.ClassVar-annotated attributes.
To Reproduce
from typing import NoReturn, Any, ClassVar
class A:
attr: ClassVar[str] = ""
def __init__(cls, *args: Any, **kwargs: Any) -> NoReturn:
raise RuntimeError
@classmethod
def f(cls) -> None:
pass
class B:
attr: ClassVar[str] = ""
@classmethod
def f(cls) -> None:
pass
Expected Behavior
No issues on any of the following:
A.f()
A.attr
B.f()
B.attr
Actual Behavior
A.f() # mypy: "Callable[[VarArg(Any), KwArg(Any)], NoReturn]" has no attribute "f" [attr-defined]
A.attr # mypy: "Callable[[VarArg(Any), KwArg(Any)], NoReturn]" has no attribute "attr" [attr-defined]
B.f()
B.attr
Your Environment
- Mypy version used: 0.990 and master branch of https://mypy-play.net/
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.10
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供されている Python 再現コードから始め、new または init が NoReturn を返すクラスを mypy がどのように表現しているかを追跡してください。classmethod と ClassVar のアクセスに対する回帰テストを追加し、A.f()、A.attr、B.f()、B.attr が問題を発生させないことを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100