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

Commit

Permalink
Get the references passing pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mawildoer committed Sep 22, 2024
1 parent 35f809d commit 4fbc245
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/faebryk/core/graphinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,5 @@ def get_referenced_gif(self) -> GraphInterfaceSelf:
except KeyErrorNotFound as ex:
raise GraphInterfaceReference.UnboundError from ex


def get_reference(self) -> T:
return self.get_referenced_gif().node
10 changes: 8 additions & 2 deletions src/faebryk/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ class constructed_field[T: "Node", O: "Node"](property, fab_field):
The constructor should return the constructed faebryk object or None.
If a faebryk object is returned, it will be added to the node.
"""

@abstractmethod
def __construct__(self, obj: T) -> O | None:
pass


class rt_field[T, O](constructed_field):
"""TODO: what does an rt_field represent? what does "rt" stand for?"""

def __init__(self, fget: Callable[[T], O]) -> None:
super().__init__()
self.func = fget
Expand Down Expand Up @@ -338,7 +340,9 @@ def handle_add(name, obj):
elif isinstance(obj, Node):
self._handle_add_node(name, obj)
else:
raise TypeError(f"Cannot handle adding field {name=} of type {type(obj)}")
raise TypeError(
f"Cannot handle adding field {name=} of type {type(obj)}"
)

def append(name, inst):
if isinstance(inst, LL_Types):
Expand Down Expand Up @@ -388,7 +392,9 @@ def setup_field(name, obj):
f'An exception occurred while constructing field "{name}"',
) from e

nonrt, rt = partition(lambda x: isinstance(x[1], constructed_field), clsfields.items())
nonrt, rt = partition(
lambda x: isinstance(x[1], constructed_field), clsfields.items()
)
for name, obj in nonrt:
setup_field(name, obj)

Expand Down
2 changes: 2 additions & 0 deletions src/faebryk/library/_F.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from faebryk.library.has_overriden_name import has_overriden_name
from faebryk.library.Operation import Operation
from faebryk.library.has_linked_pad import has_linked_pad
from faebryk.library.Reference import Reference
from faebryk.library.can_bridge import can_bridge
from faebryk.library.has_designator import has_designator
from faebryk.library.has_descriptive_properties import has_descriptive_properties
Expand Down Expand Up @@ -60,6 +61,7 @@
from faebryk.library.Footprint import Footprint
from faebryk.library.has_overriden_name_defined import has_overriden_name_defined
from faebryk.library.has_linked_pad_defined import has_linked_pad_defined
from faebryk.library.has_reference import has_reference
from faebryk.library.can_bridge_defined import can_bridge_defined
from faebryk.library.has_designator_defined import has_designator_defined
from faebryk.library.has_descriptive_properties_defined import has_descriptive_properties_defined
Expand Down
3 changes: 1 addition & 2 deletions test/library/test_reference.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from faebryk.core.graphinterface import GraphInterfaceReference
from faebryk.core.node import InitVar, Node
from faebryk.core.node import Node
from faebryk.library.Reference import Reference


Expand Down

0 comments on commit 4fbc245

Please sign in to comment.