Skip to content

Commit 5b03f9d

Browse files
committed
Typing fixes
I used several ignores that I am surprised I needed - MyPy is not behaving quite as I expected.
1 parent c71c2fd commit 5b03f9d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/labthings_fastapi/outputs/blob.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def open(self) -> io.IOBase: ...
7070
class ServerSideBlobData(BlobData, Protocol):
7171
"""A BlobOutput protocol for server-side use, i.e. including `response()`"""
7272

73+
id: Optional[uuid.UUID] = None
74+
7375
def response(self) -> Response: ...
7476

7577

@@ -171,7 +173,8 @@ def to_dict(self) -> Mapping[str, str]:
171173
if self.href == "blob://local":
172174
try:
173175
blobdata_to_url = blobdata_to_url_ctx.get()
174-
href = blobdata_to_url(self.data)
176+
# MyPy seems to miss that `self.data` is a property, hence the ignore
177+
href = blobdata_to_url(self.data) # type: ignore[arg-type]
175178
except LookupError:
176179
raise LookupError(
177180
"Blobs may only be serialised inside the "
@@ -224,7 +227,7 @@ def open(self) -> io.IOBase:
224227
@classmethod
225228
def from_bytes(cls, data: bytes) -> Self:
226229
"""Create a BlobOutput from a bytes object"""
227-
return cls.model_construct(
230+
return cls.model_construct( # type: ignore[return-value]
228231
href="blob://local",
229232
_data=BlobBytes(data, media_type=cls.default_media_type()),
230233
)
@@ -238,7 +241,7 @@ def from_temporary_directory(cls, folder: TemporaryDirectory, file: str) -> Self
238241
collected.
239242
"""
240243
file_path = os.path.join(folder.name, file)
241-
return cls.model_construct(
244+
return cls.model_construct( # type: ignore[return-value]
242245
href="blob://local",
243246
_data=BlobFile(
244247
file_path,
@@ -257,7 +260,7 @@ def from_file(cls, file: str) -> Self:
257260
temporary. If you are using temporary files, consider creating your
258261
Blob with `from_temporary_directory` instead.
259262
"""
260-
return cls.model_construct(
263+
return cls.model_construct( # type: ignore[return-value]
261264
href="blob://local",
262265
_data=BlobFile(file, media_type=cls.default_media_type()),
263266
)
@@ -326,7 +329,7 @@ def attach_to_app(self, app: FastAPI):
326329
async def blob_serialisation_context_manager(request: Request):
327330
"""Set context variables to allow blobs to be serialised"""
328331
thing_server = find_thing_server(request.app)
329-
blob_manager = thing_server.blob_data_manager
332+
blob_manager: BlobDataManager = thing_server.blob_data_manager
330333
url_for = request.url_for
331334

332335
def blobdata_to_url(blob: ServerSideBlobData) -> str:

src/labthings_fastapi/server/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self, settings_folder: Optional[str] = None):
3838

3939
app: FastAPI
4040
action_manager: ActionManager
41+
blob_data_manager: BlobDataManager
4142

4243
def set_cors_middleware(self) -> None:
4344
self.app.add_middleware(

0 commit comments

Comments
 (0)