Skip to content

Commit

Permalink
Small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
joernweissenborn committed Oct 14, 2022
1 parent ef9a765 commit a4b195a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions glotaran/model/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def fill_item_parameter_attributes(item: Item, parameters: Parameters):
The parameters.
"""
fill_item_attributes(
item, parameter_attributes(item.__class__), lambda name, label: parameters.get(label)
item, parameter_attributes(item.__class__), lambda _, label: parameters.get(label)
)


Expand Down Expand Up @@ -583,7 +583,7 @@ def strip_type_and_structure_from_attribute(attr: Attribute) -> tuple[None | lis
"""
definition = attr.type
definition = strip_option_type(definition)
structure, definition = strip_struture_type(definition)
structure, definition = strip_structure_type(definition)
definition = strip_option_type(definition, strip_type=str)
return structure, definition

Expand All @@ -607,7 +607,7 @@ def strip_option_type(definition: type, strip_type: type = NoneType) -> type:
return definition


def strip_struture_type(definition: type) -> tuple[None | list | dict, type]:
def strip_structure_type(definition: type) -> tuple[None | list | dict, type]:
"""Strip the structure from a definition.
Parameters
Expand Down
8 changes: 5 additions & 3 deletions glotaran/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, error: str):


def _load_item_from_dict(
item_type: type[Item], value: Item | Mapping, extra: dict[str, Any] = {}
item_type: type[Item], value: Item | Mapping, extra: dict[str, Any] | None = None
) -> Item:
"""Load an item from a dictionary.
Expand All @@ -73,7 +73,7 @@ def _load_item_from_dict(
The item type.
value: Item | dict
The value to load from.
extra: dict[str, Any]
extra: dict[str, Any] | None
Extra arguments for the item.
Returns
Expand All @@ -86,12 +86,14 @@ def _load_item_from_dict(
Raised if a modelitem is missing.
"""
if not isinstance(value, Item):
if extra:
value = value | extra
if issubclass(item_type, TypedItem):
try:
item_type = item_type.get_item_type_class(value["type"])
except KeyError:
raise ModelError(f"Missing 'type' for item {item_type}")
return item_type(**(value | extra))
return item_type(**(value))
return value


Expand Down

0 comments on commit a4b195a

Please sign in to comment.