Details
-
Suggestion
-
Resolution: Done
-
P3: Somewhat important
-
None
-
5.13.1
-
None
-
-
b0bfeaf894344e31b5175dbbd3ce371fae5dee5b (pyside/pyside-setup/5.14)
Description
The typing information doesn't seem to work for some types.
I have this code in test.py:
1 from PySide2.QtCore import QRect 2 from PySide2.QtGui import QPixmap 3 4 a = QPixmap() 5 6 reveal_type(a.depth()) 7 reveal_type(a.copy(rect=QRect())) 8 reveal_type(a.copy(1, 2, 3, 4)) 9 reveal_type(a.copy())
Running mypy test.py produces:
test.py:6: note: Revealed type is 'builtins.int' test.py:7: note: Revealed type is 'Any' test.py:8: note: Revealed type is 'Any' test.py:9: note: Revealed type is 'Any'
So the stubs are found and the non overloaded function on line 6 is evaluated correctly to int.
However, from the overload signature in PySide2/QtGui.pyi:
6188 class QPixmap(PySide2.QtGui.QPaintDevice): ... 6210 @typing.overload 6211 def copy(self, rect:PySide2.QtCore.QRect=...) -> PySide2.QtGui.QPixmap: ... 6212 @typing.overload 6213 def copy(self, x:int, y:int, width:int, height:int) -> PySide2.QtGui.QPixmap: ... ... 6218 def depth(self) -> int: ...
I would expect lines 7 to 9 to evaluate to QPixmap instead of Any...
See this bug on mypy, where they say that this is an issue with the typing information provided by PySide and not mypy itself: