Skip to content

Commit 55dcb00

Browse files
committed
Eliminate DocstringToMessage in errors
1 parent 25a42e5 commit 55dcb00

File tree

2 files changed

+6
-34
lines changed

2 files changed

+6
-34
lines changed

src/labthings_fastapi/exceptions.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""A submodule for custom LabThings-FastAPI Exceptions."""
22

3-
import inspect
4-
53
# The "import x as x" syntax means symbols are interpreted as being re-exported,
64
# so they won't be flagged as unused by the linter.
75
# An __all__ for this module is less than helpful, unless we have an
@@ -11,32 +9,7 @@
119
)
1210

1311

14-
class DocstringToMessage:
15-
"""A mixin to put Exception docstrings in as their default message."""
16-
17-
append_to_message: bool = True
18-
19-
def __init__(self, message: str | None = None):
20-
"""Initialise an error with a message or its docstring.
21-
22-
:param message: the optional message.
23-
"""
24-
# We ignore call-arg within this function because mypy can't know
25-
# that this is a mixin, and super() will be an exception (which does
26-
# accept a string argument to `__init__`).
27-
doc = inspect.cleandoc(self.__doc__) if self.__doc__ else None
28-
if message:
29-
if doc and self.append_to_message:
30-
super().__init__(message + "\n\n" + doc) # type: ignore[call-arg]
31-
else:
32-
super().__init__(message) # type: ignore[call-arg]
33-
elif doc:
34-
super().__init__(doc) # type: ignore[call-arg]
35-
else:
36-
super().__init__()
37-
38-
39-
class NotConnectedToServerError(DocstringToMessage, RuntimeError):
12+
class NotConnectedToServerError(RuntimeError):
4013
"""The Thing is not connected to a server.
4114
4215
This exception is called if an Action is called or
@@ -46,7 +19,7 @@ class NotConnectedToServerError(DocstringToMessage, RuntimeError):
4619
"""
4720

4821

49-
class ReadOnlyPropertyError(DocstringToMessage, AttributeError):
22+
class ReadOnlyPropertyError(AttributeError):
5023
"""A property is read-only.
5124
5225
No setter has been defined for this `.FunctionalProperty`, so

src/labthings_fastapi/thing_property.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class attribute. Documentation is in strings immediately following the
7575
from .utilities.introspection import return_type
7676
from .base_descriptor import BaseDescriptor
7777
from .exceptions import (
78-
DocstringToMessage,
7978
NotConnectedToServerError,
8079
ReadOnlyPropertyError,
8180
)
@@ -97,23 +96,23 @@ class attribute. Documentation is in strings immediately following the
9796

9897

9998
# The following exceptions are raised only when creating/setting up properties.
100-
class OverspecifiedDefaultError(DocstringToMessage, ValueError):
99+
class OverspecifiedDefaultError(ValueError):
101100
"""The default value has been specified more than once.
102101
103102
This error is raised when a `.DataProperty` is instantiated with both a
104103
``default`` value and a ``default_factory`` provided.
105104
"""
106105

107106

108-
class MissingDefaultError(DocstringToMessage, ValueError):
107+
class MissingDefaultError(ValueError):
109108
"""The default value has not been specified.
110109
111110
This error is raised when a `.DataProperty` is instantiated without a
112111
``default`` value or a ``default_factory`` function.
113112
"""
114113

115114

116-
class InconsistentTypeError(DocstringToMessage, TypeError):
115+
class InconsistentTypeError(TypeError):
117116
"""Different type hints have been given for a property.
118117
119118
Every property should have a type hint, which may be provided in a few
@@ -122,7 +121,7 @@ class InconsistentTypeError(DocstringToMessage, TypeError):
122121
"""
123122

124123

125-
class MissingTypeError(DocstringToMessage, TypeError):
124+
class MissingTypeError(TypeError):
126125
"""No type hints have been given for a property.
127126
128127
Every property should have a type hint, which may be provided in a few

0 commit comments

Comments
 (0)