qtpy
qtpy copied to clipboard
Mypy: Module `qtpy.QtCore` does not explicitly export attribute `QDateTime`
trying to do a from qtpy.QtCore import QDateTime yield the error in the title
using pyside6 and latest mypy
same with from qtpy.QtCore import Slot
... and from from qtpy.QtGui import QAction and from qtpy.QtGui import QShortcut
Hi @ZeeD thank you for the feedback and sorry for the late response! Could you try using something like this when running mypy?
mypy --always-false=PYQT5 --always-false=PYSIDE2 --always-false=PYQT6 --always-true=PYSIDE6 --follow-imports silent <file with your code>
Or how are you running mypy? For more details on the args related to the Qt bindings you can check: https://github.com/spyder-ide/qtpy#type-checker-integration
Let us know if something of the above helps or any other info that could help us reproduce the exact behavior you are experiencing!
yeah, setting the flags helped.
FYI I played with the combination and it's enough to set mypy --always-false=PYQT5 --always-false=PYSIDE2 --always-false=PYQT6 example.py to avoid the errors (but it's necessary set to false all PYQT5, PYSIDE2 and PYQT6)
Awesome! Thank you for letting us know that the args helped @ZeeD ! Do you think some more info in the README should be added about this? Otherwise I think we could close this as completed :)
my only concern is that I don't have installed PyQt5/6 nor pyside2. may you share why mypy (or qtpy) thinks it's necessary to add those global variables?
I think that is necessary since qtpy defines logic for each binding by validating those constants (so PYQT5 PYSIDE2, PYQT6 and PYSIDE6). By setting those flags then we ensure that mypy is not going to trigger logic inside qtpy which will not be supported since you just can use one binding at a time.
However, I don't have much knowledge about mypy so maybe this could be handled in a different way? (or the need for the constant flags to be a different one 🤔 ), but if you find another way to overcome the usage of such flags let us know!