Skip to content

Commit

Permalink
Fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
christiansandberg committed Sep 22, 2024
1 parent 947e46c commit c64e25a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions onedm/sdf/from_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def data_from_type(type_: Type) -> data.Data | None:
None or null is not a supported type in SDF. In this case the return value
will be None.
"""
if type_ is None:
return None
return data_from_schema(TypeAdapter(type_).core_schema)


def data_from_schema(schema: core_schema.CoreSchema) -> data.Data | None:
def data_from_schema(schema: core_schema.CoreSchema) -> data.Data:
schema_type = schema["type"]
data_type: data.Data
if schema_type == "none":
return None
if schema_type == "int":
data_type = data_from_int_schema(schema) # type: ignore
elif schema_type == "float":
Expand Down
4 changes: 4 additions & 0 deletions tests/sdf/test_from_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,7 @@ def test_label():
data = data_from_type(Annotated[int, Field(title="Test title")])

assert data.label == "Test title"


def test_none():
assert data_from_type(None) is None

0 comments on commit c64e25a

Please sign in to comment.