`safe-super` change breaks Mixin support
まだ誰も着手していません。
評価
調査の方向性
まず、提供されている Mixin と Protocol の例を mypy 1.10.0 で再現し、次に safe-super 診断とその回帰テストを追跡します。この Mixin パターンのカバレッジを追加し、既存の safe-super 警告を維持したまま、false positive が報告されなくなったことを確認します。
索引モデルが issue の本文から書いたものです。
説明
Bug Report
We want to indicate that a (super-)class must implement a specific protocol in order to inherit from a specific (sub-) class. We used to annotate self as the super class in the subclass to express this. With mypy 1.10.0 this introduces a safe-super error. Is there currently a way to express this requirement?
To Reproduce
from typing import Protocol
class HasFormValid(Protocol):
def form_valid(self, form):
pass
class SaveValidFormMixin:
def form_valid(self: HasFormValid, form):
form.save()
super().form_valid(form)
Expected Behavior
No error: Since we never actually inherit from the HasFormValid protocol, this should be safe.
Actual Behavior
mypy 1.10.0 treats HasFormValid.form_valid as trivial and warns about its usage. In this case, it is assured that HasFormValid.form_valid cannot be actually called via super().form_valid.
mypy <1.10.0 does not raise an error here.
Your Environment
- Mypy version used: mypy 1.10.0 (compiled: yes)
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.12.3
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/mypy のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
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
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
bancolombia/sentinel#23 ·
-
test md オープンCI
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
langchain-ai/deepagents#6450 ·
-
bug client
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100