Skip to content

Commit

Permalink
Specify mixins in generating a ClassDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
candleindark committed Sep 5, 2024
1 parent c003aea commit 95572ec
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/pydantic2linkml/gen_linkml.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,17 @@ def attach_note(note: str) -> None:
parents = get_parent_models(model)
local_fields = self._m_f_map[model]

# TODO: Take care of inheritance
# === Handle in heritance specifications ===
# Set parent class
is_a = parents[0].__name__ if parents else None

# TODO: Set mixins (Attached a note if mixins are used)
# Set mixins
mixins = [parent.__name__ for parent in parents[1:]]
for m in mixins:
attach_note(
f"Warning: LinkML doesn't support multiple inheritance. {m} is not "
f"specified as a parent, through the `is_a` meta slot, but as a mixin."
)

slot_usage: list[SlotDefinition] = []
notes: list[str] = []
Expand Down Expand Up @@ -345,7 +351,12 @@ def attach_note(note: str) -> None:
slot_usage.sort(key=lambda s: s.name.casefold())

return ClassDefinition(
model.__name__, is_a=is_a, slots=slots, slot_usage=slot_usage, notes=notes
model.__name__,
is_a=is_a,
mixins=mixins,
slots=slots,
slot_usage=slot_usage,
notes=notes,
)

def _establish_supporting_defs(self) -> None:
Expand Down

0 comments on commit 95572ec

Please sign in to comment.