-
-
Notifications
You must be signed in to change notification settings - Fork 153
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
How to catch QtBindingsNotFoundError #412
Comments
Good question! As of now, you could try-except the try:
import QtPy
except RuntimeError:
... The only other error raised by If you want to be sure that the error class is that specific one, you can get the error message class from the try:
import QtPy
except RuntimeError as error:
if type(error).__name__ == "QtBindingsNotFoundError":
...
else:
raise A bit inelegant, but gets the job done. To note, since the error is fundamentally an try:
import QtPy
except ImportError:
... To note, in your code, you'd want to Would you like to submit a PR? @dalthviz , any other ideas here? |
I agree with this. And perhaps we should make |
I think inheriting from The other option would be to let users |
Hmm, fair question, In terms of ideal purity, perhaps it could be argued yeah, but it would at minimum break compatibility with existing code checking for it, including via the required workaround as mentioned here. Furthermore, it would require one of the following:
And even conceptually it's a wash, since it is still at least arguably a runtime error (a compatible Qt runtime either not being installed, or not initializing correctly, and/or the runtime configuration not being set to select the correct Qt binding). Therefore, I recommend we leave that as it is, as the cost is too large and the benefit too minimal to justify a change.
That's what we more or less did before, but it resulted in a bunch of code duplication, fragility, user difficulty and the other issues discussed in issue #367 and fixed in PR #379, with some followup refinements, whereas it was difficult to find much of a use case for exposing just a few constants, exception classes and minor helpers if no binding is available, given the cost and issues involved. |
Ok, no problem. |
So you are saying you don't want to change anything and users have to catch a |
The latter, sorry. |
Should we also add some documentation about this on the |
Yeah, that would be a good idea—#395 includes your suggestion of documenting the exception hierarchy, and from this we could include the suggested workarounds from my post above. I just haven't quite found the time yet between my research, teaching and various FOSS responsibilities, sorry. |
This is perhaps a stupid question, but assuming I have only
qtpy
installed and no Qt bindings – how am I supposed to catch theQtBindingsNotFoundError
forimport qtpy
?The text was updated successfully, but these errors were encountered: