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:
Attachments
For Gerrit Dashboard: PYSIDE-1100 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
297345,8 | Support type checking with the mypy module | 5.14 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
297559,6 | signature: Fix and simplify for mypy compatibility | 5.14 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
297895,2 | signature: Fix and simplify for mypy compatibility, Part 2 | 5.14 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
300614,1 | Support type checking with the mypy module | tqtc/5.15 | pyside/tqtc-pyside-setup | Status: ABANDONED | 0 | 0 |
300616,1 | signature: Fix and simplify for mypy compatibility | tqtc/5.15 | pyside/tqtc-pyside-setup | Status: ABANDONED | 0 | 0 |
300617,1 | signature: Fix and simplify for mypy compatibility, Part 2 | tqtc/5.15 | pyside/tqtc-pyside-setup | Status: ABANDONED | 0 | 0 |