fix/metal_archives #10

Merged
Elara6331 merged 15 commits from fix/metal_archives into experimental 2024-04-18 15:50:48 +00:00
Showing only changes of commit 42c4a04b62 - Show all commits

View File

@ -58,16 +58,6 @@ class Collection(Generic[T]):
self._indexed_values[name].add(value)
self._indexed_to_objects[value].append(__object)
if not from_map:
for attribute, new_object in self.contain_given_in_attribute.items():
__object.__getattribute__(attribute).contain_collection_inside(new_object)
for attribute, new_object in self.contain_attribute_in_given.items():
new_object.contain_collection_inside(__object.__getattribute__(attribute))
for attribute, new_object in self.append_object_to_attribute.items():
__object.__getattribute__(attribute).append(new_object)
def _unmap_element(self, __object: T):
if __object.id in self._contains_ids:
self._contains_ids.remove(__object.id)
@ -186,11 +176,6 @@ class Collection(Generic[T]):
def contains(self, __object: T) -> bool:
return len(self._contained_in_sub(__object)) > 0
def _append(self, __object: T, from_map: bool = False):
print(self, __object)
self._map_element(__object, from_map=from_map)
self._data.append(__object)
def _find_object_in_self(self, __object: T) -> Optional[T]:
for name, value in __object.indexing_values:
if value is None or value == __object._default_factories.get(name, lambda: None)():
@ -211,6 +196,7 @@ class Collection(Generic[T]):
if no_sibling:
return self, None
"""
# find in siblings and all children of siblings
for parent in self.parents:
for sibling in parent.children:
@ -220,6 +206,7 @@ class Collection(Generic[T]):
o, other_object = sibling._find_object(__object, no_sibling=True)
if other_object is not None:
return o, other_object
"""
return self, None
@ -243,12 +230,19 @@ class Collection(Generic[T]):
if existing_object is None:
# append
append_to._data.append(__object)
append_to._map_element(__object, from_map=from_map)
append_to._map_element(__object)
# only modify collections if the object actually has been appended
for collection_attribute, new_object in self.contain_given_in_attribute.items():
__object.__getattribute__(collection_attribute).contain_collection_inside(new_object)
for attribute, new_object in self.append_object_to_attribute.items():
__object.__getattribute__(attribute).append(new_object)
else:
# merge
append_to._unmap_element(existing_object)
existing_object.merge(__object)
append_to._map_element(existing_object, from_map=from_map)
append_to._map_element(existing_object)
def extend(self, __iterable: Optional[Iterable[T]], from_map: bool = False):