qtpy icon indicating copy to clipboard operation
qtpy copied to clipboard

Mypy: Module `qtpy.QtCore` does not explicitly export attribute `QDateTime`

Open ZeeD opened this issue 2 years ago • 7 comments

trying to do a from qtpy.QtCore import QDateTime yield the error in the title using pyside6 and latest mypy

ZeeD avatar Apr 30 '23 15:04 ZeeD

same with from qtpy.QtCore import Slot

ZeeD avatar Apr 30 '23 15:04 ZeeD

... and from from qtpy.QtGui import QAction and from qtpy.QtGui import QShortcut

ZeeD avatar Apr 30 '23 15:04 ZeeD

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!

dalthviz avatar May 18 '23 23:05 dalthviz

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)

ZeeD avatar May 20 '23 11:05 ZeeD

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 :)

dalthviz avatar May 22 '23 18:05 dalthviz

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?

ZeeD avatar May 23 '23 10:05 ZeeD

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!

dalthviz avatar May 23 '23 19:05 dalthviz