From 2acc91a606900e70b906bd340eff249b0194a638 Mon Sep 17 00:00:00 2001 From: iopapamanoglou Date: Tue, 27 Aug 2024 23:48:02 +0200 Subject: [PATCH] cleaner handle_parent_add --- src/faebryk/core/node.py | 7 ++----- src/faebryk/core/trait.py | 23 +++++++++++------------ test/libs/picker/test_jlcpcb.py | 5 ++++- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/faebryk/core/node.py b/src/faebryk/core/node.py index c2b996cf..9cd402aa 100644 --- a/src/faebryk/core/node.py +++ b/src/faebryk/core/node.py @@ -381,15 +381,12 @@ def _handle_add_node(self, name: str, node: "Node"): ) node.parent.connect(self.children, LinkNamedParent.curry(name)) - node.on_obj_set() + node._handle_added_to_parent() def _remove_child(self, node: "Node"): node.parent.disconnect_parent() - # TODO rename - def on_obj_set(self): ... - - def handle_added_to_parent(self): ... + def _handle_added_to_parent(self): ... def get_graph(self): return self.self_gif.G diff --git a/src/faebryk/core/trait.py b/src/faebryk/core/trait.py index 71d6db9c..3a473cf2 100644 --- a/src/faebryk/core/trait.py +++ b/src/faebryk/core/trait.py @@ -60,18 +60,6 @@ def __preinit__(self) -> None: assert issubclass(self._trait, Trait) assert self._trait is not TraitImpl - def handle_added_to_parent(self): - self.on_obj_set() - - def on_obj_set(self): ... - - def remove_obj(self): - self._obj = None - - def handle_duplicate(self, other: "TraitImpl", node: Node): - assert other is not self - raise TraitAlreadyExists(node, self) - @property def obj(self) -> Node: p = self.get_parent() @@ -100,6 +88,17 @@ def implements(self, trait: type): return issubclass(self._trait, trait) + # Overwriteable -------------------------------------------------------------------- + + def _handle_added_to_parent(self): + self.on_obj_set() + + def on_obj_set(self): ... + + def handle_duplicate(self, other: "TraitImpl", node: Node): + assert other is not self + raise TraitAlreadyExists(node, self) + # override this to implement a dynamic trait def is_implemented(self): return True diff --git a/test/libs/picker/test_jlcpcb.py b/test/libs/picker/test_jlcpcb.py index 4d659d21..ae03dc22 100644 --- a/test/libs/picker/test_jlcpcb.py +++ b/test/libs/picker/test_jlcpcb.py @@ -8,6 +8,8 @@ import faebryk.library._F as F import faebryk.libs.picker.lcsc as lcsc from faebryk.core.module import Module +from faebryk.core.parameter import Parameter +from faebryk.core.util import get_children from faebryk.libs.logging import setup_basic_logging from faebryk.libs.picker.jlcpcb.jlcpcb import JLCPCB_DB from faebryk.libs.picker.jlcpcb.pickers import add_jlcpcb_pickers @@ -92,7 +94,8 @@ def satisfies_requirements(self): ) for req, res in zip( - self.requirement.PARAMs.get_all(), self.result.PARAMs.get_all() + get_children(self.requirement, direct_only=True, types=Parameter), + get_children(self.result, direct_only=True, types=Parameter), ): req = req.get_most_narrow() res = res.get_most_narrow()