Skip to content

Commit

Permalink
try subclassing instead of protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Aug 12, 2024
1 parent 406ee00 commit 9dc42da
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions dsp_permissions_scripts/doap/doap_model.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

from typing import Protocol
from typing import Self

from pydantic import BaseModel
from pydantic import ConfigDict
from pydantic import model_validator

from dsp_permissions_scripts.models.group import Group
Expand All @@ -13,12 +13,14 @@
class Doap(BaseModel):
"""Model representing a DOAP, containing the target, the scope and the IRI of the DOAP."""

model_config = ConfigDict(arbitrary_types_allowed=True)

target: DoapTarget
scope: PermissionScope
doap_iri: str


class DoapTarget(Protocol):
class DoapTarget:
"""
A DOAP can be defined for either a Group, or for a ResourceClass, or for a Property,
or for a combination of ResourceClass and Property.
Expand All @@ -28,12 +30,12 @@ class DoapTarget(Protocol):
project_iri: str


class GroupDoapTarget(BaseModel):
class GroupDoapTarget(BaseModel, DoapTarget):
project_iri: str
group: Group


class EntityDoapTarget(BaseModel):
class EntityDoapTarget(BaseModel, DoapTarget):
project_iri: str
resource_class: str | None = None
property: str | None = None
Expand Down

0 comments on commit 9dc42da

Please sign in to comment.