Skip to content

Commit 658f6d8

Browse files
committed
fix(errors): put built-in exception bases before DBusFastError in MRO
1 parent cdc4432 commit 658f6d8

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

src/dbus_fast/errors.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@ class DBusFastError(Exception):
88
"""
99

1010

11-
class SignatureBodyMismatchError(DBusFastError, ValueError):
11+
class SignatureBodyMismatchError(ValueError, DBusFastError):
1212
pass
1313

1414

15-
class InvalidSignatureError(DBusFastError, ValueError):
15+
class InvalidSignatureError(ValueError, DBusFastError):
1616
pass
1717

1818

19-
class InvalidAddressError(DBusFastError, ValueError):
19+
class InvalidAddressError(ValueError, DBusFastError):
2020
pass
2121

2222

2323
class AuthError(DBusFastError):
2424
pass
2525

2626

27-
class InvalidMessageError(DBusFastError, ValueError):
27+
class InvalidMessageError(ValueError, DBusFastError):
2828
pass
2929

3030

31-
class InvalidIntrospectionError(DBusFastError, ValueError):
31+
class InvalidIntrospectionError(ValueError, DBusFastError):
3232
pass
3333

3434

@@ -40,22 +40,22 @@ class SignalDisabledError(DBusFastError):
4040
pass
4141

4242

43-
class InvalidBusNameError(DBusFastError, TypeError):
43+
class InvalidBusNameError(TypeError, DBusFastError):
4444
def __init__(self, name: str) -> None:
4545
super().__init__(f"invalid bus name: {name}")
4646

4747

48-
class InvalidObjectPathError(DBusFastError, TypeError):
48+
class InvalidObjectPathError(TypeError, DBusFastError):
4949
def __init__(self, path: str) -> None:
5050
super().__init__(f"invalid object path: {path}")
5151

5252

53-
class InvalidInterfaceNameError(DBusFastError, TypeError):
53+
class InvalidInterfaceNameError(TypeError, DBusFastError):
5454
def __init__(self, name: str) -> None:
5555
super().__init__(f"invalid interface name: {name}")
5656

5757

58-
class InvalidMemberNameError(DBusFastError, TypeError):
58+
class InvalidMemberNameError(TypeError, DBusFastError):
5959
def __init__(self, member: str) -> None:
6060
super().__init__(f"invalid member name: {member}")
6161

tests/test_errors.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,29 @@ def test_type_error_subclasses_preserved(err_cls: type[BaseException]) -> None:
7777
assert issubclass(err_cls, TypeError)
7878

7979

80+
def test_value_error_subclass_mro_order() -> None:
81+
"""Built-in ``ValueError`` must precede ``DBusFastError`` in the MRO.
82+
83+
This ordering ensures ``super().__init__`` routes through
84+
``ValueError.__init__`` rather than skipping straight to
85+
``Exception.__init__``, preserving the behavior of the historical
86+
single-inheritance ``ValueError`` subclasses.
87+
"""
88+
mro = InvalidSignatureError.__mro__
89+
assert mro.index(ValueError) < mro.index(DBusFastError)
90+
91+
92+
def test_type_error_subclass_mro_order() -> None:
93+
"""Built-in ``TypeError`` must precede ``DBusFastError`` in the MRO.
94+
95+
Same rationale as the ``ValueError`` MRO test: keeps ``super().__init__``
96+
routing through ``TypeError.__init__`` to match the original
97+
single-inheritance ``TypeError`` subclasses.
98+
"""
99+
mro = InvalidBusNameError.__mro__
100+
assert mro.index(TypeError) < mro.index(DBusFastError)
101+
102+
80103
def test_dbus_fast_error_catches_value_error_subclass() -> None:
81104
with pytest.raises(DBusFastError):
82105
raise SignatureBodyMismatchError("body mismatch")

0 commit comments

Comments
 (0)