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

PR: Make warning usage consistant and refine messages #398

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions qtpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@


class PythonQtError(RuntimeError):
"""Error raised if no bindings could be selected."""
"""Generic error superclass for QtPy."""


class PythonQtWarning(Warning):
"""Warning if some features are not implemented in a binding."""
class PythonQtWarning(RuntimeWarning):
"""Warning class for QtPy."""


class PythonQtValueError(ValueError):
Expand All @@ -79,7 +79,7 @@ class PythonQtValueError(ValueError):
class QtBindingsNotFoundError(PythonQtError):
"""Error raised if no bindings could be selected."""
_msg = 'No Qt bindings could be found'

def __init__(self):
super().__init__(self._msg)

Expand All @@ -106,7 +106,7 @@ class QtModuleNotInOSError(QtModuleNotFoundError):
class QtModuleNotInQtVersionError(QtModuleNotFoundError):
"""Raised when a module is not implemented in the current Qt version."""
_msg = '{name} does not exist in {version}.'

def __init__(self, *, name, msg=None, **msg_kwargs):
global QT5, QT6
version = 'Qt5' if QT5 else 'Qt6'
Expand Down Expand Up @@ -264,8 +264,11 @@ def __init__(self, *, missing_package=None, **superclass_kwargs):
# If a correct API name is passed to QT_API and it could not be found,
# switches to another and informs through the warning
if API != initial_api and binding_specified:
warnings.warn('Selected binding "{}" could not be found, '
'using "{}"'.format(initial_api, API), RuntimeWarning)
warnings.warn(
f'Selected binding {initial_api!r} could not be found; '
f'falling back to {API!r}',
PythonQtWarning,
)


# Set display name of the Qt API
Expand All @@ -282,10 +285,10 @@ def __init__(self, *, missing_package=None, **superclass_kwargs):
def _warn_old_minor_version(name, old_version, min_version):
"""Warn if using a Qt or binding version no longer supported by QtPy."""
warning_message = (
"{name} version {old_version} is not supported by QtPy. "
"To ensure your application works correctly with QtPy, "
"please upgrade to {name} {min_version} or later.".format(
name=name, old_version=old_version, min_version=min_version))
f'{name} version {old_version} is not supported by QtPy. '
'To ensure your application works correctly with QtPy, '
f'please upgrade to {name} {min_version} or later.'
)
warnings.warn(warning_message, PythonQtWarning)


Expand Down