Bad error with Protocol and class heirarchy with overloads
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu bằng cách chạy bản tái hiện PyQt6 được cung cấp với mypy 1.9.0 và kiểm tra cách các định nghĩa chỉ mục overloaded được so sánh giữa QAbstractItemModel, QFileSystemModel và protocol. So sánh kết quả với pyright và pytype như đã được báo cáo; hoàn thành khi incompatibility được xử lý chính xác hoặc diagnostic giải thích rõ vấn đề thực tế.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 20.6k
- Fork
- 3.3k
- Merge trung bình
- 1 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 54
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/mypy
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug topic-configuration topic-error-reporting
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Issue tương tự
-
link-check link-check:sphinx-theme
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenHands/extensions#626 · 1 bình luận ·
-
Change observation tooltip text Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
CSCfi/sd-search-api#39 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100