Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ZeeD opened this issue Apr 30, 2023 · 7 comments
Open

Comments

@ZeeD
Copy link

ZeeD commented Apr 30, 2023

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

@ZeeD
Copy link
Author

ZeeD commented Apr 30, 2023

same with from qtpy.QtCore import Slot

@ZeeD
Copy link
Author

ZeeD commented Apr 30, 2023

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

@dalthviz
Copy link
Member

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!

@ZeeD
Copy link
Author

ZeeD commented May 20, 2023

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)

@dalthviz dalthviz removed the type:Bug label May 22, 2023
@dalthviz
Copy link
Member

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

@ZeeD
Copy link
Author

ZeeD commented May 23, 2023

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?

@dalthviz
Copy link
Member

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 dalthviz changed the title Mypy: Module "qtpy.QtCore" does not explicitly export attribute "QDateTime" Mypy: Module qtpy.QtCore does not explicitly export attribute QDateTime Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants