Description
Bug Report
Most likely related to Issue #11004 , but adding here in case there is more going on. The python/typing discussion here helped me understand this is a mypy
issue.
To Reproduce
I am using mypy==0.961
exclusively (not any other static type checker; e.g. pyright
, pyre
, pytyped
, etc.) in basic
mode (not strict
).
I've imported qtpy
with PySide6
in python==3.8.10
on Windows 10 x64-bit in VSCode 1.68.1
. I am writing a subclass that overwrites QTabWidget
.
PySide6
is a binding of the C++ Qt6
library using shiboken6
. C++ does not natively support keyword arguments and PySide6
has chosen to support only exporting optional arguments from Qt6
as keyword arguments.
The documentation for PySide6 seems to indicate my stubs below are correct
import typing
from qtpy import QtWidgets, QtGui
class MyTabWidget(QtWidgets.QTabWidget):
@typing.overload
def addTab(
self,
__widget: QtWidgets.QWidget,
__arg__2: str,
) -> int:
...
@typing.overload
def addTab(
self,
__widget: QtWidgets.QWidget,
__icon: QtGui.QIcon | QtGui.QPixmap,
__label: str,
) -> int:
...
def addTab(
self,
widget: QtWidgets.QWidget,
icon: QtGui.QIcon | QtGui.QPixmap | None,
label: str,
) -> int:
# Implementation here
However, mypy
complains that the overloaded method doesn't accept all possible arguments:
The workaround of specifying the first signature as
@typing.overload
def addTab(
self,
__widget: QtWidgets.QWidget,
icon: None = None,
__arg__2: str,
) -> int:
...
does not work for me because positional arguments cannot come after keyword arguments.
I also tried:
@typing.overload
def addTab( # noqa: D102
self,
__widget: QtWidgets.QWidget,
__arg__2: str,
) -> int:
...
@typing.overload
def addTab( # noqa: D102
self,
__widget: QtWidgets.QWidget,
__icon: QtGui.QIcon | QtGui.QPixmap | str,
__label: str,
) -> int:
...
def addTab(
self,
widget: QtWidgets.QWidget,
icon: QtGui.QIcon | QtGui.QPixmap | str | None,
label: str,
) -> int:
# Implementation here
but that didn't work either.
Expected Behavior
Overloads are properly understood.
Actual Behavior
Overloads error that not all possible arguments are accepted.
Your Environment
- Mypy version used:
0.961
- Mypy command-line flags:
pyproject.toml
[tool.mypy]
python_executable = ".venv/Scripts/python.exe"
python_version = "3.8"
disallow_untyped_defs = true
warn_return_any = true
warn_unused_configs = true
warn_unused_ignores = true
warn_redundant_casts = true
show_error_codes = true
no_pretty = true
show_column_numbers = true
plugins = [
"pydantic.mypy"
]
exclude = [
'stubs/',
'[.]venv/',
'build/',
'dist/',
'ci/'
]
fast_module_lookup = true
- Mypy configuration options from
mypy.ini
(and other config files): See above - Python version used:
3.8.10
x64-bit - Operating system and version:
Windows 10 x64-bit, Verson 20H2