Bad error with Protocol and class heirarchy with overloads
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza ejecutando la reproducción de PyQt6 proporcionada con mypy 1.9.0 e inspecciona cómo se comparan las definiciones de índices sobrecargadas entre QAbstractItemModel, QFileSystemModel y el protocolo. Compara el resultado con pyright y pytype según lo informado; se considera terminado cuando la incompatibilidad se gestiona correctamente o el diagnóstico explica claramente el problema real.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools, tooling
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100