Skip to content

Commit e9ed606

Browse files
committed
Standardise on :return: and :raise X:
1 parent cc5af86 commit e9ed606

File tree

15 files changed

+36
-37
lines changed

15 files changed

+36
-37
lines changed

src/labthings_fastapi/actions/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def run(self) -> None:
224224
225225
See `.Invocation.status` for status values.
226226
227-
:raises Exception: any exception raised in the action function will
227+
:raise Exception: any exception raised in the action function will
228228
propagate through this method. Usually, this will just cause the
229229
thread to terminate after setting ``status`` to ``ERROR`` and
230230
saving the exception to ``self._exception``.
@@ -461,7 +461,7 @@ def action_invocation(
461461
462462
:return: Details of the invocation.
463463
464-
:raises HTTPException: with code ``404`` if the invocation is not
464+
:raise HTTPException: with code ``404`` if the invocation is not
465465
found.
466466
"""
467467
try:
@@ -500,7 +500,7 @@ def action_invocation_output(id: uuid.UUID, _blob_manager: BlobIOContextDep):
500500
:return: The output of the invocation, as a `pydantic.BaseModel`
501501
instance. If this is a `.Blob`, it may be returned directly.
502502
503-
:raises HTTPException: with code ``404`` if the invocation is not
503+
:raise HTTPException: with code ``404`` if the invocation is not
504504
found.
505505
"""
506506
with self._invocations_lock:
@@ -539,7 +539,7 @@ def delete_invocation(id: uuid.UUID) -> None:
539539
540540
:param id: The unique ID of the invocation to cancel (from the URL).
541541
542-
:raises HTTPException: with code ``404`` if the invocation is not
542+
:raise HTTPException: with code ``404`` if the invocation is not
543543
found, or ``503`` if the invocation is not currently running.
544544
"""
545545
with self._invocations_lock:

src/labthings_fastapi/client/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def _get_link(obj: dict, rel: str) -> Mapping:
5050
:return: a dictionary representing the link. It should contain at least
5151
``href`` and ``rel`` keys.
5252
53-
:raises ObjectHasNoLinksError: if there is no ``links`` item.
54-
:raises KeyError: if there is no link with the specified ``rel`` value.
53+
:raise ObjectHasNoLinksError: if there is no ``links`` item.
54+
:raise KeyError: if there is no link with the specified ``rel`` value.
5555
"""
5656
if "links" not in obj:
5757
raise ObjectHasNoLinksError(f"Can't find any links on {obj}.")
@@ -177,7 +177,7 @@ def invoke_action(self, path: str, **kwargs):
177177
178178
:return: the output value of the action.
179179
180-
:raises RuntimeError: is raised if the action does not complete successfully.
180+
:raise RuntimeError: is raised if the action does not complete successfully.
181181
"""
182182
for k in kwargs.keys():
183183
if isinstance(kwargs[k], ClientBlobOutput):

src/labthings_fastapi/client/in_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def add_action(
188188
the ``name`` in the supplied action descriptor.
189189
:param action: an `.ActionDescriptor` to be wrapped.
190190
191-
:raises DependencyNameClashError: if dependencies are inconsistent.
191+
:raise DependencyNameClashError: if dependencies are inconsistent.
192192
"""
193193

194194
@wraps(action.func)

src/labthings_fastapi/dependencies/invocation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def raise_if_set(self):
144144
if cancel_event.is_set():
145145
raise InvocationCancelledError()
146146
147-
:raises InvocationCancelledError: if the event has been cancelled.
147+
:raise InvocationCancelledError: if the event has been cancelled.
148148
"""
149149
if self.is_set():
150150
raise InvocationCancelledError("The action was cancelled.")
@@ -159,7 +159,7 @@ def sleep(self, timeout: float):
159159
160160
:param timeout: The time to sleep for, in seconds.
161161
162-
:raises InvocationCancelledError: if the event has been cancelled.
162+
:raise InvocationCancelledError: if the event has been cancelled.
163163
"""
164164
if self.wait(timeout):
165165
raise InvocationCancelledError("The action was cancelled.")

src/labthings_fastapi/dependencies/thing_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def find_thing_server(app: FastAPI) -> ThingServer:
5353
5454
:return: the `.ThingServer` that owns the ``app``.
5555
56-
:raises RuntimeError: if there is no `.ThingServer` associated
56+
:raise RuntimeError: if there is no `.ThingServer` associated
5757
with the current FastAPI application. This should only happen
5858
if this function is called on a `fastapi.FastAPI` instance
5959
that was not created by a `.ThingServer`.

src/labthings_fastapi/descriptors/action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def emit_changed_event(self, obj: Thing, status: str):
201201
:param obj: The `.Thing` on which the action is being observed.
202202
:param status: The status of the action, to be sent to observers.
203203
204-
:raises NotConnectedToServerError: if the Thing calling the action is not
204+
:raise NotConnectedToServerError: if the Thing calling the action is not
205205
connected to a server with a running event loop.
206206
"""
207207
try:

src/labthings_fastapi/descriptors/property.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(
101101
:param getter: A function that gets the value of the property.
102102
:param setter: A function that sets the value of the property.
103103
104-
:raises ValueError: if the initial value or type are missing or incorrectly
104+
:raise ValueError: if the initial value or type are missing or incorrectly
105105
specified.
106106
"""
107107
if getter and initial_value is not None:
@@ -217,7 +217,7 @@ def emit_changed_event(self, obj: Thing, value: Any) -> None:
217217
:param obj: the `.Thing` to which we are attached.
218218
:param value: the new property value, to be sent to observers.
219219
220-
:raises NotConnectedToServerError: if the Thing that is calling the property
220+
:raise NotConnectedToServerError: if the Thing that is calling the property
221221
update is not connected to a server with a running event loop.
222222
"""
223223
runner = obj._labthings_blocking_portal

src/labthings_fastapi/example_things/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ class ThingWithBrokenAffordances(Thing):
125125
def broken_action(self):
126126
"""Do something that raises an exception.
127127
128-
:raises RuntimeError: every time.
128+
:raise RuntimeError: every time.
129129
"""
130130
raise RuntimeError("This is a broken action")
131131

132132
@thing_property
133133
def broken_property(self):
134134
"""Raise an exception when the property is accessed.
135135
136-
:raises RuntimeError: every time.
136+
:raise RuntimeError: every time.
137137
"""
138138
raise RuntimeError("This is a broken property")
139139

@@ -144,7 +144,7 @@ class ThingThatCantInstantiate(Thing):
144144
def __init__(self):
145145
"""Fail to initialise.
146146
147-
:raises RuntimeError: every time.
147+
:raise RuntimeError: every time.
148148
"""
149149
raise RuntimeError("This thing can't be instantiated")
150150

@@ -155,7 +155,7 @@ class ThingThatCantStart(Thing):
155155
def __enter__(self):
156156
"""Fail to start the thing.
157157
158-
:raises RuntimeError: every time.
158+
:raise RuntimeError: every time.
159159
"""
160160
raise RuntimeError("This thing can't start")
161161

src/labthings_fastapi/outputs/blob.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def __init__(self, file_path: str, media_type: str, **kwargs):
228228
attributes. This may be used to stop temporary directories
229229
from being garbage collected while the `.Blob` exists.
230230
231-
:raises IOError: if the file specified does not exist.
231+
:raise IOError: if the file specified does not exist.
232232
"""
233233
if not os.path.exists(file_path):
234234
raise IOError("Tried to return a file that doesn't exist.")
@@ -348,10 +348,10 @@ def retrieve_data(self) -> Self:
348348
349349
:return: the `.Blob` object (i.e. ``self``), after retrieving the data.
350350
351-
:raises ValueError: if the ``href`` is set as ``"blob://local"`` but
351+
:raise ValueError: if the ``href`` is set as ``"blob://local"`` but
352352
the ``_data`` attribute has not been set. This happens when the
353353
`.Blob` is being constructed using `.Blob.from_bytes` or similar.
354-
:raises LookupError: if the `.Blob` is being constructed from a URL
354+
:raise LookupError: if the `.Blob` is being constructed from a URL
355355
and the URL does not correspond to a `.BlobData` instance that
356356
exists on this server (i.e. one that has been previously created
357357
and added to the `.BlobManager` as the result of a previous action).
@@ -389,7 +389,7 @@ def to_dict(self) -> Mapping[str, str]:
389389
:return: a JSON-serialisable dictionary with a URL that allows
390390
the `.Blob` to be downloaded from the `.BlobManager`.
391391
392-
:raises LookupError: if the context variable providing access to the
392+
:raise LookupError: if the context variable providing access to the
393393
`.BlobManager` is not available. This usually means the `.Blob` is
394394
being serialised somewhere other than the output of an action.
395395
"""
@@ -442,7 +442,7 @@ def data(self) -> ServerSideBlobData:
442442
443443
:return: the data store wrapping data on disk or in memory.
444444
445-
:raises ValueError: if there is no data stored on disk or in memory.
445+
:raise ValueError: if there is no data stored on disk or in memory.
446446
"""
447447
if self._data is None:
448448
raise ValueError("This Blob has no data.")
@@ -583,7 +583,7 @@ class MyImageBlob(Blob):
583583
584584
:return: a subclass of `.Blob` with the specified default media type.
585585
586-
:raises ValueError: if the media type contains ``'`` or ``\``.
586+
:raise ValueError: if the media type contains ``'`` or ``\``.
587587
"""
588588
if "'" in media_type or "\\" in media_type:
589589
raise ValueError("media_type must not contain single quotes or backslashes")
@@ -631,7 +631,7 @@ def add_blob(self, blob: ServerSideBlobData) -> uuid.UUID:
631631
:return: a unique ID identifying the data. This forms part of
632632
the URL to download the data.
633633
634-
:raises ValueError: if the `.ServerSideBlobData` object already
634+
:raise ValueError: if the `.ServerSideBlobData` object already
635635
has an ``id`` attribute but is not in the dictionary of
636636
data. This suggests the object has been added to another
637637
`.BlobDataManager`, which should never happen.

src/labthings_fastapi/outputs/mjpeg_stream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ async def next_frame(self) -> int:
230230
231231
:return: the index of the next frame to arrive.
232232
233-
:raises StopAsyncIteration: if the stream has stopped.
233+
:raise StopAsyncIteration: if the stream has stopped.
234234
"""
235235
async with self.condition:
236236
await self.condition.wait()
@@ -317,7 +317,7 @@ def add_frame(self, frame: bytes, portal: BlockingPortal) -> None:
317317
The blocking portal may be obtained with a dependency, in
318318
`labthings_fastapi.dependencies.blocking_portal.BlockingPortal`.
319319
320-
:raises ValueError: if the supplied frame does not start with the JPEG
320+
:raise ValueError: if the supplied frame does not start with the JPEG
321321
start bytes and end with the end bytes.
322322
"""
323323
if not (

0 commit comments

Comments
 (0)