Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(xmlupload): serialise values in classes #1272

Merged
merged 12 commits into from
Nov 14, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

from abc import ABC
from abc import abstractmethod
from collections.abc import Sequence
from dataclasses import dataclass
from typing import Any


@dataclass(frozen=True)
class SerialiseProperty:
property_name: str
values: list[SerialiseValue]
values: Sequence[SerialiseValue]

def serialise(self) -> dict[str, Any]:
"""Serialise the property and all its values."""
Expand Down
6 changes: 3 additions & 3 deletions src/dsp_tools/commands/xmlupload/resource_create_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _make_date_value(value: XMLValue) -> dict[str, Any]:


def _transform_into_decimal_prop(prop: XMLProperty, permissions_lookup: dict[str, Permissions]) -> SerialiseProperty:
vals: list[SerialiseValue] = [_transform_into_decimal_value(v, permissions_lookup) for v in prop.values]
vals = [_transform_into_decimal_value(v, permissions_lookup) for v in prop.values]
return SerialiseProperty(property_name=prop.name, values=vals)


Expand All @@ -327,7 +327,7 @@ def _transform_into_decimal_value(value: XMLValue, permissions_lookup: dict[str,


def _transform_into_geometry_prop(prop: XMLProperty, permissions_lookup: dict[str, Permissions]) -> SerialiseProperty:
vals: list[SerialiseValue] = [_transform_into_geometry_value(v, permissions_lookup) for v in prop.values]
vals = [_transform_into_geometry_value(v, permissions_lookup) for v in prop.values]
return SerialiseProperty(property_name=prop.name, values=vals)


Expand Down Expand Up @@ -443,7 +443,7 @@ def _make_list_value(value: XMLValue, iri_lookup: dict[str, str]) -> dict[str, A
def _transform_text_prop(
prop: XMLProperty, permissions_lookup: dict[str, Permissions], iri_resolver: IriResolver
) -> SerialiseProperty:
values: list[SerialiseValue] = []
values = []
Nora-Olivia-Ammann marked this conversation as resolved.
Show resolved Hide resolved
for val in prop.values:
match val.value:
case str():
Expand Down