Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a two-element list for BooleanType.literals #370

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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