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

Odd code found for PyQt5 in tests/conftest.py: importing too much? #504

Open
StSav012 opened this issue Nov 29, 2024 · 4 comments
Open

Odd code found for PyQt5 in tests/conftest.py: importing too much? #504

StSav012 opened this issue Nov 29, 2024 · 4 comments

Comments

@StSav012
Copy link
Contributor

Shouldn't there be QtCore instead of just Qt?

try:
from PyQt5 import Qt
versions += f"PyQt: {Qt.PYQT_VERSION_STR} - Qt: {Qt.QT_VERSION_STR}"
except ImportError:

For PyQt6, it is so:

try:
from PyQt6 import QtCore
versions += (
f"PyQt: {QtCore.PYQT_VERSION_STR} - Qt: {QtCore.QT_VERSION_STR}"
)
except ImportError:

@dalthviz
Copy link
Member

Hi @StSav012 thanks for the report! Checking for me that code works 🤔

image

What version of PyQt5 are you using for it to raise an error?

@StSav012
Copy link
Contributor Author

That's embarrassing for me. I must have checked it wrongly. But anyway, the import seems to load just everything:

from PyQt5 import Qt  # for the following line to work
# Now, `PyQt5.__all__` seems to be populated.
from PyQt5 import *

print(
    set(Qt.__dir__()) == \
    set(
        sum(
            (
                m.__dir__()
                for n, m in sys.modules.items()
                if n.startswith("PyQt5.Qt") and n != "PyQt5.Qt"
            ),
            [],
        )
    )
)

Does it necessary to get only a version string?

@StSav012 StSav012 changed the title Odd code found for PyQt5 in tests/conftest.py: always raises an exception Odd code found for PyQt5 in tests/conftest.py: importing too much? Dec 16, 2024
@dalthviz
Copy link
Member

Does it necessary to get only a version string?

I think that's the case. The import is only meant to check that the binding is importable/available and to get the relevant info about the version available. Not totally sure if there is also some other reason why for the PyQt5 case the Qt import is done though 🤔 Is there any other reason to use the from PyQt5 import Qt to get the version @ccordoba12 ?

@ccordoba12
Copy link
Member

Is there any other reason to use the from PyQt5 import Qt to get the version @ccordoba12 ?

Probably for compatibility with PyQt4. I'd say we should change it to from PyQt5 import QtCore if it works without problems.

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

3 participants