Self is not rejected when used as a PEP 695 type parameter bound
まだ誰も着手していません。
評価
調査の方向性
test-data/unit/check-selftype.test の1480行目あたりから始め、issueのPEP 695の例を再現してください。他の無効な場所に使用されている既存のSelf検証を追跡し、その後、型パラメーターのboundまたは制約に対するテストカバレッジを追加してください。完了の条件は、既存のSelfテストが引き続き成功したまま、例に対してmypyがエラーを報告することです。
索引モデルが issue の本文から書いたものです。
説明
Bug Report
Self is only valid in the specific locations listed in PEP 673 and Mypy already rejects several invalid locations.
See: https://github.com/python/mypy/blob/ae39cdb2fba8908eeff6ec8d6b88879c62495fcc/test-data/unit/check-selftype.test#L1480
It seems one location wasn't covered: using Self as the bound (or constraint) of a PEP 695 type parameter.
To Reproduce:
from typing import Self
class Foo:
def fails[T: Self](self: T) -> None: pass
Expected Behavior
Mypy should reject Self here with an error.
From a quick look at other type checkers: pyright and ty treat it as an invalid/generic TypeVar bound (TypeVar upper bound cannot be generic), while zuban rejects it with the same message mypy already uses elsewhere,
Self type is only allowed in annotations within class definition.
Actual Behavior
No error is reported.
Your Environment
Mypy version: https://github.com/python/mypy/commit/ae39cdb2fba8908eeff6ec8d6b88879c62495fcc
Python version: 3.12
TLDR; originally spotted while working on #21928 See: https://github.com/python/mypy/pull/21928#issuecomment-5557910054
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 12時間
- マージ済み PR(30日)
- 58
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/mypy のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
bug topic-configuration topic-error-reporting
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
bug topic-attrs
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
似ている issue
-
essnmx good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
-
[Feature] 奇物选择添加优先级 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
syfoud/Simulated_Scepter#174 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Giskard-AI/giskard-oss#2840 · コメント 1 件 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success オープンarea: repo bug perceived difficulty: 2
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
yeti-platform/yeti#1380 ·