[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Various issues with PyQt stubs
From:       Phil Thompson <phil () riverbankcomputing ! com>
Date:       2016-05-19 16:32:29
Message-ID: A1AB884A-58F6-405C-9760-D3CEF569E742 () riverbankcomputing ! com
[Download RAW message or body]

Some of these are simply bugs (which I will get around to) others (specifically the \
"incompatible with supertype") are more of a problem.

It isn't clear (to me anyway) what PEP 484 is trying to achieve. I had thought that \
it was to provide a way of describing an API in a formal way so that other tools \
could be written to exploit the additional information. Type checking tools such as \
mypy would be just one example. However mypy seems only to be interested in APIs that \
follow a certain pattern and considers APIs that don't follow that pattern to be \
erroneous - even though they are perfectly valid as far as Python is concerned.

It would be much better if mypy were to just ignore APIs (or give a warning) that it \
can't usefully analyse. Then at least it would be possible to use the mypy parser to \
validate stub files. I have tried explaining this to the relevent developers (as well \
as to the PyCharm developers who use stub files for auto-completion information) but \
with little success.

I have no personal need for stub files. It would be helpful if somebody who had a \
genuine need were to look at the PyQt stub files and see if they are useful, or if \
they need to be changed to be useful, or if they would be useful if the downstream \
tools were a bit more mature.

Phil

On 18 May 2016, at 9:47 pm, Florian Bruhin <me@the-compiler.org> wrote:
> 
> Hi,
> 
> I tried to start using mypy now that PyQt has stubs.
> 
> Since I can't easily install stubs currently I opted to add them to a
> repo (copied out after I ran configure.py in the PyQt repo). When I
> then run mypy with --check-untyped-defs and MYPYDIR set to the stubs
> dir, I get various issues mypy reports about the stub files.
> 
> The first one is obvious, a QtGui import is missing from various stub
> files:
> 
> misc/stubs/PyQt5/QtPrintSupport.pyi: note: In function "metric":
> misc/stubs/PyQt5/QtPrintSupport.pyi:177: error: Name 'QtGui' is not defined
> misc/stubs/PyQt5/QtPrintSupport.pyi: note: At top level:
> misc/stubs/PyQt5/QtPrintSupport.pyi:184a version with stubs : error: Name 'QtGui' \
> is not defined [...]
> 
> I fixed this for the stub modules I use, but more might be affected:
> https://github.com/The-Compiler/qutebrowser/commit/f372644124793467865b9a324a3ce77f9f0ff358
>  
> The same happens for QtNetwork in QtWebKitWidgets.pyi:
> 
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi: note: In function "load":
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi:105: error: Name 'QtNetwork' is not defined
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi:229: error: Name 'QtNetwork' is not defined
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi: note: In function "acceptNavigationRequest":
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi:497: error: Invalid type "QtNetwork"
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi: note: In function "downloadRequested":
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi:501: error: Invalid type "QtNetwork"
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi: note: In function "unsupportedContent":
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi:502: error: Invalid type "QtNetwork"
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi: note: In function "networkAccessManager":
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi:542: error: Invalid type "QtNetwork"
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi: note: In function "setNetworkAccessManager":
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi:543: error: Invalid type "QtNetwork"
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi: note: In function "load":
> 	misc/stubs/PyQt5/QtWebKitWidgets.pyi:619: error: Name 'QtNetwork' is not defined
> 
> With that fixed, there are still a lot of errors about incompatible
> types. I've looked into the first one:
> 
> 	misc/stubs/PyQt5/QtGui.pyi: note: In class "QPixmap":
> 	misc/stubs/PyQt5/QtGui.pyi:181: error: Return type of "devicePixelRatio" \
> incompatible with supertype "QPaintDevice" 
> Looking at the Qt documentation, it seems indeed like there's
> QPaintDevice::devicePixelRatio which returns an int, which is
> overridden by QPixmap::devicePixelRatio returning a qreal (aka float)?
> 
> Not sure how that'd best be expressed in the stubs, but it seems like
> MyPy doesn't like how it looks currently...
> 
> The others:
> 
> 	misc/stubs/PyQt5/QtGui.pyi: note: In class "QBitmap":
> 	misc/stubs/PyQt5/QtGui.pyi:255: error: Argument 1 of "swap" incompatible with \
> supertype "QPixmap"  misc/stubs/PyQt5/QtGui.pyi:256: error: Signature of \
> "transformed" incompatible with supertype "QPixmap"  misc/stubs/PyQt5/QtGui.pyi: \
> note: In class "QImage":  misc/stubs/PyQt5/QtGui.pyi:2077: error: Return type of \
> "devicePixelRatio" incompatible with supertype "QPaintDevice"  \
> misc/stubs/PyQt5/QtGui.pyi: note: In class "QMatrix4x4":  \
> misc/stubs/PyQt5/QtGui.pyi:2543: error: Overloaded function signatures 1 and 2 \
> overlap with incompatible return types  misc/stubs/PyQt5/QtGui.pyi: note: In class \
> "QWindow":  misc/stubs/PyQt5/QtGui.pyi:3933: error: Argument 1 of "setParent" \
> incompatible with supertype "QObject"  misc/stubs/PyQt5/QtGui.pyi: note: In class \
> "QPaintDeviceWindow":  misc/stubs/PyQt5/QtGui.pyi:3942: error: Definition of \
> "devicePixelRatio" in base class "QWindow" is incompatible with definition in base \
> class "QPaintDevice"  misc/stubs/PyQt5/QtGui.pyi: note: In class "QPdfWriter":
> 	misc/stubs/PyQt5/QtGui.pyi:5309: error: Signature of "setPageSize" incompatible \
> with supertype "QPagedPaintDevice"  misc/stubs/PyQt5/QtGui.pyi: note: In class \
> "QTextList":  misc/stubs/PyQt5/QtGui.pyi:7378: error: Argument 1 of "setFormat" \
> incompatible with supertype "QTextObject"  misc/stubs/PyQt5/QtGui.pyi: note: In \
> class "QTextTable":  misc/stubs/PyQt5/QtGui.pyi:7591: error: Argument 1 of \
> "setFormat" incompatible with supertype "QTextObject"  misc/stubs/PyQt5/QtGui.pyi: \
> note: In class "QTransform":  misc/stubs/PyQt5/QtGui.pyi:7712: error: Overloaded \
> function signatures 3 and 4 overlap with incompatible return types  \
> misc/stubs/PyQt5/QtWidgets.pyi: note: In class "QWidget":  \
> misc/stubs/PyQt5/QtWidgets.pyi:195: error: Signature of "setParent" incompatible \
> with supertype "QObject"  misc/stubs/PyQt5/QtWidgets.pyi: note: In class \
> "QAbstractItemView":  misc/stubs/PyQt5/QtWidgets.pyi:721: error: Signature of \
> "update" incompatible with supertype "QWidget"  misc/stubs/PyQt5/QtWidgets.pyi: \
> note: In class "QApplication":  misc/stubs/PyQt5/QtWidgets.pyi:1102: error: \
> Signature of "topLevelAt" incompatible with supertype "QGuiApplication"  \
> misc/stubs/PyQt5/QtWidgets.pyi: note: In class "QFileSystemModel":  \
> misc/stubs/PyQt5/QtWidgets.pyi:3139: error: Signature of "parent" incompatible with \
> supertype "QAbstractItemModel"  misc/stubs/PyQt5/QtWidgets.pyi:3139: error: \
> Signature of "parent" incompatible with supertype "QObject"  \
> misc/stubs/PyQt5/QtWidgets.pyi: note: In class "QGraphicsPixmapItem":  \
> misc/stubs/PyQt5/QtWidgets.pyi:4288: error: Signature of "paint" incompatible with \
> supertype "QGraphicsItem"  misc/stubs/PyQt5/QtWidgets.pyi: note: In class \
> "QGraphicsSimpleTextItem":  misc/stubs/PyQt5/QtWidgets.pyi:4313: error: Signature \
> of "paint" incompatible with supertype "QGraphicsItem"  \
> misc/stubs/PyQt5/QtWidgets.pyi: note: In class "QGraphicsTextItem":  \
> misc/stubs/PyQt5/QtWidgets.pyi:4399: error: Signature of "paint" incompatible with \
> supertype "QGraphicsItem"  misc/stubs/PyQt5/QtWidgets.pyi: note: In class \
> "QGraphicsProxyWidget":  misc/stubs/PyQt5/QtWidgets.pyi:4570: error: Signature of \
> "paint" incompatible with supertype "QGraphicsWidget"  \
> misc/stubs/PyQt5/QtWidgets.pyi:4570: error: Signature of "paint" incompatible with \
> supertype "QGraphicsItem"  misc/stubs/PyQt5/QtWidgets.pyi:4571: error: Signature of \
> "setGeometry" incompatible with supertype "QGraphicsWidget"  \
> misc/stubs/PyQt5/QtWidgets.pyi: note: In class "QGraphicsView":  \
> misc/stubs/PyQt5/QtWidgets.pyi:5027: error: Signature of "render" incompatible with \
> supertype "QWidget"  misc/stubs/PyQt5/QtWidgets.pyi: note: In class "QHeaderView":
> 	misc/stubs/PyQt5/QtWidgets.pyi:5191: error: Argument 1 of "initStyleOption" \
> incompatible with supertype "QFrame"  misc/stubs/PyQt5/QtWidgets.pyi:5216: error: \
> Signature of "scrollTo" incompatible with supertype "QAbstractItemView"  \
> misc/stubs/PyQt5/QtWidgets.pyi: note: In class "QListWidget":  \
> misc/stubs/PyQt5/QtWidgets.pyi:5901: error: Argument 1 of "closePersistentEditor" \
> incompatible with supertype "QAbstractItemView"  \
> misc/stubs/PyQt5/QtWidgets.pyi:5902: error: Argument 1 of "openPersistentEditor" \
> incompatible with supertype "QAbstractItemView"  misc/stubs/PyQt5/QtWidgets.pyi: \
> note: In class "QPlainTextEdit":  misc/stubs/PyQt5/QtWidgets.pyi:6592: error: \
> Signature of "find" incompatible with supertype "QWidget"  \
> misc/stubs/PyQt5/QtWidgets.pyi: note: In class "QProxyStyle":  \
> misc/stubs/PyQt5/QtWidgets.pyi:6732: error: Signature of "polish" incompatible with \
> supertype "QCommonStyle"  misc/stubs/PyQt5/QtWidgets.pyi:6732: error: Signature of \
> "polish" incompatible with supertype "QStyle"  misc/stubs/PyQt5/QtWidgets.pyi:6740: \
> error: Signature of "standardPixmap" incompatible with supertype "QCommonStyle"  \
> misc/stubs/PyQt5/QtWidgets.pyi:6740: error: Signature of "standardPixmap" \
> incompatible with supertype "QStyle"  misc/stubs/PyQt5/QtWidgets.pyi:6748: error: \
> Signature of "subControlRect" incompatible with supertype "QCommonStyle"  \
> misc/stubs/PyQt5/QtWidgets.pyi:6748: error: Signature of "subControlRect" \
> incompatible with supertype "QStyle"  misc/stubs/PyQt5/QtWidgets.pyi:6749: error: \
> Signature of "subElementRect" incompatible with supertype "QCommonStyle"  \
> misc/stubs/PyQt5/QtWidgets.pyi:6749: error: Signature of "subElementRect" \
> incompatible with supertype "QStyle"  misc/stubs/PyQt5/QtWidgets.pyi:6750: error: \
> Signature of "sizeFromContents" incompatible with supertype "QCommonStyle"  \
> misc/stubs/PyQt5/QtWidgets.pyi:6750: error: Signature of "sizeFromContents" \
> incompatible with supertype "QStyle"  misc/stubs/PyQt5/QtWidgets.pyi: note: In \
> class "QRubberBand":  misc/stubs/PyQt5/QtWidgets.pyi:6791: error: Signature of \
> "resize" incompatible with supertype "QWidget"  misc/stubs/PyQt5/QtWidgets.pyi: \
> note: In class "QSplashScreen":  misc/stubs/PyQt5/QtWidgets.pyi:7180: error: \
> Signature of "repaint" incompatible with supertype "QWidget"  \
> misc/stubs/PyQt5/QtWidgets.pyi: note: In class "QStackedLayout":  \
> misc/stubs/PyQt5/QtWidgets.pyi:7284: error: Return type of "addWidget" incompatible \
> with supertype "QLayout"  misc/stubs/PyQt5/QtWidgets.pyi: note: In class \
> "QStylePainter":  misc/stubs/PyQt5/QtWidgets.pyi:8174: error: Signature of "begin" \
> incompatible with supertype "QPainter"  misc/stubs/PyQt5/QtWidgets.pyi: note: In \
> class "QTableWidget":  misc/stubs/PyQt5/QtWidgets.pyi:8528: error: Argument 1 of \
> "closePersistentEditor" incompatible with supertype "QAbstractItemView"  \
> misc/stubs/PyQt5/QtWidgets.pyi:8529: error: Argument 1 of "openPersistentEditor" \
> incompatible with supertype "QAbstractItemView"  misc/stubs/PyQt5/QtWidgets.pyi: \
> note: In class "QTextEdit":  misc/stubs/PyQt5/QtWidgets.pyi:8783: error: Signature \
> of "find" incompatible with supertype "QWidget"  misc/stubs/PyQt5/QtWidgets.pyi: \
> note: In class "QTreeWidget":  misc/stubs/PyQt5/QtWidgets.pyi:9256: error: \
> Signature of "closePersistentEditor" incompatible with supertype \
> "QAbstractItemView"  misc/stubs/PyQt5/QtWidgets.pyi:9257: error: Signature of \
> "openPersistentEditor" incompatible with supertype "QAbstractItemView"  \
> misc/stubs/PyQt5/QtCore.pyi: note: In class "QAbstractTableModel":  \
> misc/stubs/PyQt5/QtCore.pyi:1899: error: Signature of "parent" incompatible with \
> supertype "QAbstractItemModel"  misc/stubs/PyQt5/QtCore.pyi: note: In class \
> "QAbstractListModel":  misc/stubs/PyQt5/QtCore.pyi:1910: error: Signature of \
> "parent" incompatible with supertype "QAbstractItemModel"  \
> misc/stubs/PyQt5/QtCore.pyi: note: In class "QIdentityProxyModel":  \
> misc/stubs/PyQt5/QtCore.pyi:3746: error: Signature of "parent" incompatible with \
> supertype "QAbstractItemModel"  misc/stubs/PyQt5/QtCore.pyi:3746: error: Signature \
> of "parent" incompatible with supertype "QObject"  misc/stubs/PyQt5/QtCore.pyi: \
> note: In class "QStringListModel":  misc/stubs/PyQt5/QtCore.pyi:6911: error: \
> Signature of "data" incompatible with supertype "QAbstractItemModel"  \
> misc/stubs/PyQt5/QtCore.pyi: note: In class "QTemporaryFile":  \
> misc/stubs/PyQt5/QtCore.pyi:6975: error: Signature of "open" incompatible with \
> supertype "QFile"  misc/stubs/PyQt5/QtCore.pyi:6975: error: Signature of "open" \
> incompatible with supertype "QIODevice"  misc/stubs/PyQt5/QtPrintSupport.pyi: note: \
> In class "QPrinter":  misc/stubs/PyQt5/QtPrintSupport.pyi:264: error: Signature of \
> "setPageMargins" incompatible with supertype "QPagedPaintDevice"  \
> misc/stubs/PyQt5/QtNetwork.pyi: note: In class "QHostAddress":  \
> misc/stubs/PyQt5/QtNetwork.pyi:415: error: Overloaded function signatures 2 and 3 \
> overlap with incompatible return types  misc/stubs/PyQt5/QtNetwork.pyi: note: In \
> class "QSslSocket":  misc/stubs/PyQt5/QtNetwork.pyi:1605: error: Signature of \
> "connectToHost" incompatible with supertype "QAbstractSocket"  \
> misc/stubs/PyQt5/QtNetwork.pyi:1654: error: Overloaded function signatures 1 and 2 \
> overlap with incompatible return types  misc/stubs/PyQt5/QtNetwork.pyi:1662: error: \
> Overloaded function signatures 1 and 2 overlap with incompatible return types  \
> misc/stubs/PyQt5/QtWebKit.pyi: note: In function "webFrame":  \
> misc/stubs/PyQt5/QtWebKit.pyi:111: error: Name 'QWebFrame' is not defined  \
> misc/stubs/PyQt5/QtWebKitWidgets.pyi: note: In class "QGraphicsWebView":  \
> misc/stubs/PyQt5/QtWebKitWidgets.pyi:89: error: Signature of "sizeHint" \
> incompatible with supertype "QGraphicsWidget"  \
> misc/stubs/PyQt5/QtWebKitWidgets.pyi:89: error: Signature of "sizeHint" \
> incompatible with supertype "QGraphicsLayoutItem"  \
> misc/stubs/PyQt5/QtWebKitWidgets.pyi:94: error: Signature of "setGeometry" \
> incompatible with supertype "QGraphicsWidget" 
> Florian
> 
> -- 
> http://www.the-compiler.org | me@the-compiler.org (Mail/XMPP)
> GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
> I love long mails! | http://email.is-not-s.ms/
> _______________________________________________
> PyQt mailing list    PyQt@riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic