Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# uv pip compile --extra dev pyproject.toml --output-file dev-requirements.txt
alabaster==1.0.0
# via sphinx
annotated-doc==0.0.4
# via fastapi
annotated-types==0.7.0
# via pydantic
anyio==4.9.0
Expand Down Expand Up @@ -45,12 +47,6 @@ click==8.2.1
# uvicorn
codespell==2.4.1
# via labthings-fastapi (pyproject.toml)
colorama==0.4.6
# via
# click
# pytest
# sphinx
# uvicorn
coverage==7.9.2
# via pytest-cov
cssutils==2.11.1
Expand Down Expand Up @@ -83,7 +79,7 @@ exceptiongroup==1.3.0
# via
# anyio
# pytest
fastapi==0.116.1
fastapi==0.135.1
# via labthings-fastapi (pyproject.toml)
fastapi-cli==0.0.8
# via fastapi
Expand Down Expand Up @@ -169,8 +165,6 @@ natsort==8.4.0
# via domdf-python-tools
numpy==2.2.6
# via labthings-fastapi (pyproject.toml)
orjson==3.11.0
# via fastapi
packaging==25.0
# via
# pytest
Expand All @@ -187,14 +181,14 @@ pluggy==1.6.0
# pytest-cov
pycodestyle==2.14.0
# via flake8
pydantic==2.10.6
pydantic==2.12.5
# via
# labthings-fastapi (pyproject.toml)
# fastapi
# fastapi-cloud-cli
# pydantic-extra-types
# pydantic-settings
pydantic-core==2.27.2
pydantic-core==2.41.5
# via pydantic
pydantic-extra-types==2.10.5
# via fastapi
Expand Down Expand Up @@ -355,10 +349,11 @@ typing-extensions==4.14.1
# typer
# typing-inspection
# uvicorn
typing-inspection==0.4.1
# via pydantic-settings
ujson==5.10.0
# via fastapi
typing-inspection==0.4.2
# via
# fastapi
# pydantic
# pydantic-settings
urllib3==2.5.0
# via
# requests
Expand All @@ -369,6 +364,8 @@ uvicorn==0.35.0
# fastapi
# fastapi-cli
# fastapi-cloud-cli
uvloop==0.22.1
# via uvicorn
watchfiles==1.1.0
# via uvicorn
webencodings==0.5.1
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"pydantic ~= 2.10.6",
"pydantic ~= 2.12",
"numpy>=1.20",
"jsonschema",
"typing_extensions",
"anyio ~=4.0",
"httpx",
"fastapi[all]>=0.115.0",
"fastapi[all]~=0.135.0",
"zeroconf >=0.28.0",
]

Expand Down
2 changes: 1 addition & 1 deletion src/labthings_fastapi/outputs/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@

:return: a list of UUIDs for all registered `.LocalBlobData` objects.
"""
return list(cls._all_blobdata.keys())

Check warning on line 301 in src/labthings_fastapi/outputs/blob.py

View workflow job for this annotation

GitHub Actions / coverage

301 line is not covered with tests

@property
def id(self) -> uuid.UUID:
Expand Down Expand Up @@ -614,7 +614,7 @@
"""
return core_schema.no_info_wrap_validator_function(
cls._validate,
BlobModel.__get_pydantic_core_schema__(BlobModel, handler),
BlobModel.__pydantic_core_schema__,
serialization=core_schema.wrap_serializer_function_ser_schema(
cls._serialize,
is_field_serializer=False,
Expand Down Expand Up @@ -901,8 +901,8 @@
try:
blob = LocalBlobData.from_id(blob_id)
return blob.response()
except KeyError as e:
raise HTTPException(status_code=404, detail="Blob not found") from e

Check warning on line 905 in src/labthings_fastapi/outputs/blob.py

View workflow job for this annotation

GitHub Actions / coverage

904-905 lines are not covered with tests


def url_to_id(url: str) -> uuid.UUID | None:
Expand Down
13 changes: 4 additions & 9 deletions src/labthings_fastapi/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from weakref import WeakSet
from pydantic import BaseModel, ConfigDict, Field, RootModel, create_model
from pydantic.dataclasses import dataclass
from pydantic_core import SchemaError

from labthings_fastapi.exceptions import UnsupportedConstraintError
from .introspection import EmptyObject
Expand Down Expand Up @@ -129,13 +128,13 @@
:raises UnsupportedConstraintError: if constraints are provided for an
unsuitable type, for example `allow_inf_nan` for an `int` property, or
any constraints for a `BaseModel` subclass.
:raises SchemaError: if other errors prevent Pydantic from creating a schema
:raises RuntimeError: if other errors prevent Pydantic from creating a schema
for the generated model.
"""
try: # This needs to be a `try` as basic types are not classes
if issubclass(model, BaseModel):
if constraints:
raise UnsupportedConstraintError(

Check warning on line 137 in src/labthings_fastapi/utilities/__init__.py

View workflow job for this annotation

GitHub Actions / coverage

137 line is not covered with tests
"Constraints may only be applied to plain types, not Models."
)
return model
Expand All @@ -148,14 +147,10 @@
root=(model, Field(**constraints)),
__base__=LabThingsRootModelWrapper,
)
except SchemaError as e:
for error in e.errors():
if error["loc"][-1] in constraints:
key = error["loc"][-1]
raise UnsupportedConstraintError(
f"Constraint {key} is not supported for type {model!r}."
) from e
except RuntimeError as e:
if "Unable to apply constraint" in str(e):
raise UnsupportedConstraintError(str(e)) from e
raise e

Check warning on line 153 in src/labthings_fastapi/utilities/__init__.py

View workflow job for this annotation

GitHub Actions / coverage

153 line is not covered with tests


def model_to_dict(model: Optional[BaseModel]) -> Dict[str, Any]:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def test_bad_property_constraints():
"""Test that bad constraints raise errors at definition time."""

class BadConstraintThing(lt.Thing):
bad_prop: int = lt.property(default=0, allow_inf_nan=False)
bad_prop: str = lt.property(default="hello", allow_inf_nan=True)

# Some constraints cause errors when the model is built. So far
# I believe only allow_inf_nan on int does this.
Expand Down
Loading