Skip to content

Commit 189f2c1

Browse files
Move module __getattr__ to top for better visibility and remove underscore from _getattr_missing_optional_dep
Co-authored-by: Carlos Cordoba <[email protected]>
1 parent c614210 commit 189f2c1

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

qtpy/QtGui.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""Provides QtGui classes and functions."""
1010

1111
from . import PYQT6, PYQT5, PYSIDE2, PYSIDE6, QtModuleNotInstalledError
12-
from .utils import _getattr_missing_optional_dep
12+
from .utils import getattr_missing_optional_dep
1313

1414

1515
_missing_optional_names = {}
@@ -32,6 +32,11 @@
3232
'QOpenGLWindow',
3333
}
3434

35+
def __getattr__(name):
36+
"""Custom getattr to chain and wrap errors due to missing optional deps."""
37+
raise getattr_missing_optional_dep(
38+
name, module_name=__name__, optional_names=_missing_optional_names)
39+
3540

3641
if PYQT5:
3742
from PyQt5.QtGui import *
@@ -170,7 +175,3 @@ def movePositionPatched(
170175
QSinglePointEvent.globalX = lambda self: self.globalPosition().toPoint().x()
171176
QSinglePointEvent.globalY = lambda self: self.globalPosition().toPoint().y()
172177

173-
def __getattr__(name):
174-
"""Custom getattr to chain and wrap errors due to missing optional deps."""
175-
raise _getattr_missing_optional_dep(
176-
name, module_name=__name__, optional_names=_missing_optional_names)

qtpy/QtWidgets.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
"""Provides widget classes and functions."""
1010

1111
from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtModuleNotInstalledError
12-
from .utils import _getattr_missing_optional_dep
12+
from .utils import getattr_missing_optional_dep
1313

1414

1515
_missing_optional_names = {}
1616

17+
def __getattr__(name):
18+
"""Custom getattr to chain and wrap errors due to missing optional deps."""
19+
raise getattr_missing_optional_dep(
20+
name, module_name=__name__, optional_names=_missing_optional_names)
21+
1722

1823
if PYQT5:
1924
from PyQt5.QtWidgets import *
@@ -80,8 +85,3 @@
8085
QDialog.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs)
8186
QMenu.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs)
8287

83-
84-
def __getattr__(name):
85-
"""Custom getattr to chain and wrap errors due to missing optional deps."""
86-
raise _getattr_missing_optional_dep(
87-
name, module_name=__name__, optional_names=_missing_optional_names)

qtpy/tests/optional_deps/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# See https://github.com/spyder-ide/qtpy/pull/387/
55

66

7-
from qtpy.utils import _getattr_missing_optional_dep
7+
from qtpy.utils import getattr_missing_optional_dep
88
from .optional_dep import ExampleClass
99

1010

@@ -23,5 +23,5 @@
2323

2424
def __getattr__(name):
2525
"""Custom getattr to chain and wrap errors due to missing optional deps."""
26-
raise _getattr_missing_optional_dep(
26+
raise getattr_missing_optional_dep(
2727
name, module_name=__name__, optional_names=_missing_optional_names)

qtpy/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _wrap_missing_optional_dep_error(
2424
return qtpy_error
2525

2626

27-
def _getattr_missing_optional_dep(name, module_name, optional_names):
27+
def getattr_missing_optional_dep(name, module_name, optional_names):
2828
"""Wrap AttributeError in a special error if it matches."""
2929
attr_error = AttributeError(f'module {module_name!r} has no attribute {name!r}')
3030
if name in optional_names:

0 commit comments

Comments
 (0)