Skip to content

Commit

Permalink
merge: Use a two-element list for BooleanType.literals
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuestengecko committed Jan 8, 2024
2 parents 1a1d604 + b9c4791 commit 2167a5e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
27 changes: 22 additions & 5 deletions capellambse/model/common/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ def __init__(
attr: str,
*,
aslist: type[element.ElementList] | None = None,
list_extra_args: cabc.Mapping[str, t.Any] | None = None,
):
"""Create an AttrProxyAccessor.
Expand All @@ -1053,9 +1054,17 @@ def __init__(
returned. If not None, must be a subclass of
:class:`~capellambse.model.common.element.ElementList`. It
will be used to return a list of all matched objects.
list_extra_args
Extra arguments to pass to the
:class:`~capellambse.model.common.element.ElementList`
constructor.
"""
del class_
super().__init__(element.GenericElement, aslist=aslist)
super().__init__(
element.GenericElement,
aslist=aslist,
list_extra_args=list_extra_args,
)
self.attr = attr

def __get__(self, obj, objtype=None):
Expand Down Expand Up @@ -1174,9 +1183,13 @@ def __init__(
*,
aslist: type[element.ElementList],
) -> None:
super().__init__(class_, attr, aslist=aslist)
super().__init__(
class_,
attr,
aslist=aslist,
list_extra_args={"fixed_length": 2},
)
assert self.aslist is not None
self.aslist.fixed_length = 2

@contextlib.contextmanager
def purge_references(
Expand Down Expand Up @@ -1847,15 +1860,19 @@ class ElementListCouplingMixin(element.ElementList[T], t.Generic[T]):
"""

_accessor: WritableAccessor[T]
fixed_length: t.ClassVar[int] = 0

def __init__(
self, *args: t.Any, parent: element.ModelObject, **kw: t.Any
self,
*args: t.Any,
parent: element.ModelObject,
fixed_length: int = 0,
**kw: t.Any,
) -> None:
assert type(self)._accessor

super().__init__(*args, **kw)
self._parent = parent
self.fixed_length = fixed_length

@t.overload
def __setitem__(self, index: int, value: T) -> None:
Expand Down
6 changes: 5 additions & 1 deletion capellambse/model/crosslayer/information/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ class DataType(c.GenericElement):

@c.xtype_handler(None)
class BooleanType(DataType):
literals = c.DirectProxyAccessor(datavalue.LiteralBooleanValue)
literals = c.DirectProxyAccessor(
datavalue.LiteralBooleanValue,
aslist=c.ElementList,
list_extra_args={"fixed_length": 2},
)
default = c.RoleTagAccessor("ownedDefaultValue")


Expand Down

0 comments on commit 2167a5e

Please sign in to comment.