Skip to content

Commit

Permalink
refactor: Renaming and remove redundancies
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Feb 17, 2023
1 parent 0714273 commit 6e4c327
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
12 changes: 5 additions & 7 deletions capellambse/model/common/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"ReferenceSearchingAccessor",
"ElementListCouplingMixin",
"RoleTagAccessor",
"InvalidChangeRequest",
"InvalidModificationError",
]

import abc
Expand All @@ -47,8 +47,8 @@
_C = t.TypeVar("_C", bound="ElementListCouplingMixin")


class InvalidChangeRequest(Exception):
"""Raised when a change request is invalid."""
class InvalidModificationError(Exception):
"""Raised when a modification would result in an invalid model."""


class NonUniqueMemberError(ValueError):
Expand Down Expand Up @@ -1260,9 +1260,9 @@ class RoleTagAccessor(DirectProxyAccessor[T]):
def __init__(
self,
role_tag: str,
class_: type[T] | type[element.GenericElement] | None = None,
class_: type[T] | None = None,
*,
aslist: type[element.ElementList[T]] | None = None,
aslist: type[element.ElementList] | None = None,
list_extra_args: dict[str, t.Any] | None = None,
) -> None:
super().__init__(
Expand Down Expand Up @@ -1303,8 +1303,6 @@ def create(
assert isinstance(elmlist._parent, element.GenericElement)

if not type_hints:
if not self.class_:
raise ValueError("Need type hint for creating object")
type_hints = (self.class_.__name__,)

kw["_xmltag"] = self.role_tag
Expand Down
10 changes: 3 additions & 7 deletions capellambse/model/crosslayer/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def name(self, value: str) -> None:
raise TypeError("Name has to be a string")

if self._constructed:
raise c.InvalidChangeRequest(
raise c.InvalidModificationError(
"This won't have any effect. The name is inferred from "
"`.type`."
)
Expand Down Expand Up @@ -153,9 +153,7 @@ class Component(c.GenericElement):
)
ports = c.DirectProxyAccessor(fa.ComponentPort, aslist=c.ElementList)
physical_ports = c.DirectProxyAccessor(PhysicalPort, aslist=c.ElementList)
parts = c.RoleTagAccessor[Part](
"ownedFeatures", Part, aslist=c.ElementList # type: ignore[arg-type]
)
parts = c.RoleTagAccessor("ownedFeatures", Part, aslist=c.ElementList)
representing_parts = c.ReferenceSearchingAccessor(
Part, "type", aslist=c.ElementList
)
Expand Down Expand Up @@ -197,9 +195,7 @@ class ComponentPkg(c.GenericElement):
exchanges = c.DirectProxyAccessor(
fa.ComponentExchange, aslist=c.ElementList
)
parts = c.RoleTagAccessor[Part](
"ownedParts", Part, aslist=c.ElementList # type: ignore[arg-type]
)
parts = c.RoleTagAccessor("ownedParts", Part, aslist=c.ElementList)
state_machines = c.DirectProxyAccessor(
capellacommon.StateMachine, aslist=c.ElementList
)
Expand Down
14 changes: 7 additions & 7 deletions capellambse/model/crosslayer/information/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ class Property(c.GenericElement):
"aggregationKind", modeltypes.AggregationKind, default="UNSET"
)
type = c.AttrProxyAccessor(c.GenericElement, "abstractType")
default_value = c.RoleTagAccessor[datavalue.LiteralValue](
"ownedDefaultValue"
default_value = c.RoleTagAccessor(
"ownedDefaultValue", datavalue.LiteralValue
)
min = c.RoleTagAccessor[datavalue.LiteralValue]("ownedMinValue")
max = c.RoleTagAccessor[datavalue.LiteralValue]("ownedMaxValue")
null_value = c.RoleTagAccessor[datavalue.LiteralValue]("ownedNullValue")
min_card = c.RoleTagAccessor[datavalue.LiteralValue]("ownedMinCard")
max_card = c.RoleTagAccessor[datavalue.LiteralValue]("ownedMaxCard")
min = c.RoleTagAccessor("ownedMinValue", datavalue.LiteralValue)
max = c.RoleTagAccessor("ownedMaxValue", datavalue.LiteralValue)
null_value = c.RoleTagAccessor("ownedNullValue", datavalue.LiteralValue)
min_card = c.RoleTagAccessor("ownedMinCard", datavalue.LiteralValue)
max_card = c.RoleTagAccessor("ownedMaxCard", datavalue.LiteralValue)
association = c.ReferenceSearchingAccessor(Association, "roles")


Expand Down
2 changes: 1 addition & 1 deletion capellambse/model/crosslayer/information/datavalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ValuePart(c.GenericElement):
referenced_property = c.AttrProxyAccessor(
c.GenericElement, "referencedProperty"
)
value = c.RoleTagAccessor[LiteralValue]("ownedValue")
value = c.RoleTagAccessor("ownedValue", LiteralValue)


@c.xtype_handler(None)
Expand Down
14 changes: 7 additions & 7 deletions capellambse/model/crosslayer/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ class Scenario(c.GenericElement):
InstanceRole, aslist=c.ElementList
)
messages = c.DirectProxyAccessor(SequenceMessage, aslist=c.ElementList)
events = c.RoleTagAccessor[EventOperation](
"ownedEvents", aslist=c.MixedElementList # type: ignore[arg-type]
events = c.RoleTagAccessor(
"ownedEvents", EventOperation, aslist=c.MixedElementList
)
fragments = c.RoleTagAccessor[InteractionFragment](
fragments = c.RoleTagAccessor(
"ownedInteractionFragments",
aslist=c.MixedElementList, # type: ignore[arg-type]
InteractionFragment,
aslist=c.MixedElementList,
)
time_lapses = c.RoleTagAccessor[Event](
"ownedTimeLapses",
aslist=c.MixedElementList, # type: ignore[arg-type]
time_lapses = c.RoleTagAccessor(
"ownedTimeLapses", Event, aslist=c.MixedElementList
)


Expand Down

0 comments on commit 6e4c327

Please sign in to comment.