Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
cleaner handle_parent_add
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Aug 27, 2024
1 parent b882590 commit 2acc91a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
7 changes: 2 additions & 5 deletions src/faebryk/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions src/faebryk/core/trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion test/libs/picker/test_jlcpcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 2acc91a

Please sign in to comment.