Bad error with Protocol and class heirarchy with overloads
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
調査の方向性
まず、提供された PyQt6 の再現コードを mypy 1.9.0 で実行し、QAbstractItemModel、QFileSystemModel、プロトコルの間でオーバーロードされたインデックス定義がどのように比較されるかを調べます。結果を報告されている pyright および pytype と比較します。不互換性が正しく処理されるか、診断が実際の問題を明確に説明できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
I'm trying to implement a protocol that mimics QFileSystemModel so that I can use that protocol to define a new custom class. The protocol definition is generating a mypy error ( error: Definition of "index" in base class "QAbstractItemModel" is incompatible with definition in base class "FileSystemModelProtocol")
I've checked with pyright and pytype and neither report an error.
To Reproduce
import typing
from PyQt6 import QtCore, QtGui
class FileSystemModelProtocol(typing.Protocol):
"""Define the subset of QFileSystemModel methods used...for defining a class with the same behavior"""
@typing.overload
def index(self, row: int, column: int, parent: QtCore.QModelIndex = ...) -> QtCore.QModelIndex: ...
@typing.overload
def index(self, row: typing.Optional[str], column: int = ...) -> QtCore.QModelIndex: ...
def index(self, row: typing.Optional[int | str] = ..., column: int = ..., parent: QtCore.QModelIndex = ...) -> QtCore.QModelIndex: ...
class CustomFileSystemModel(QtGui.QFileSystemModel, FileSystemModelProtocol): # error: Definition of "index" in base class "QAbstractItemModel" is incompatible with definition in base class "FileSystemModelProtocol"
pass
class TableModel(QtCore.QAbstractTableModel, FileSystemModelProtocol):
def index_from_str(self, path: str) -> QtCore.QModelIndex:
return QtCore.QModelIndex() # TODO: lookup with path
def index(self, row: typing.Optional[int | str] = None, column: int = 0, parent: QtCore.QModelIndex = QtCore.QModelIndex()) -> QtCore.QModelIndex:
if isinstance(row, str):
return self.index_from_str(row)
if isinstance(row, int):
return super().index(row, column, parent)
return QtCore.QModelIndex()
c = CustomFileSystemModel()
t = TableModel()
Expected Behavior
No errors, or a better explanation of what is wrong.
Actual Behavior
error: Definition of "index" in base class "QAbstractItemModel" is incompatible with definition in base class "FileSystemModelProtocol" [misc]
Your Environment
- Mypy version used:
- mypy 1.9.0 (compiled: yes)
- Mypy command-line flags:
- none
- Mypy configuration options from
mypy.ini(and other config files): - none
- Python version used:
Python 3.11.7
PyQt6==6.6.1
- 主要言語
- 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