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

Commit

Permalink
Replace init with new
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Aug 23, 2024
1 parent fcf2ce6 commit 64d2b9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 3 additions & 5 deletions new_holders_flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import typer

from faebryk.core.module import Module
from faebryk.core.node import d_field, if_list, rt_field
from faebryk.core.parameter import Parameter
from faebryk.core.util import as_unit
from faebryk.library.can_bridge_defined import can_bridge_defined
from faebryk.library.Electrical import Electrical
from faebryk.library.has_designator_prefix import has_designator_prefix
from faebryk.library.has_designator_prefix_defined import has_designator_prefix_defined
from faebryk.library.has_simple_value_representation import (
has_simple_value_representation,
Expand Down Expand Up @@ -46,7 +44,7 @@ def bla_dep2(self):
return self.bla_voltage + (10 * P.V)

# dynamic trait
@rt_field
@L.rt_field
def bridge(self):
return can_bridge_defined(self.anode, self.cathode)

Expand Down Expand Up @@ -76,9 +74,9 @@ def __preinit__(self):

class LED2_WITHEXTRAT_IFS(LED2):
extra: list[Electrical] = field(default_factory=lambda: times(2, Electrical))
extra2: list[Electrical] = if_list(2, Electrical)
extra2: list[Electrical] = L.if_list(2, Electrical)

@rt_field
@L.rt_field
def bridge(self):
return can_bridge_defined(self.extra2[0], self.extra2[1])

Expand Down
8 changes: 7 additions & 1 deletion src/faebryk/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,12 @@ def setup_gen_alias(name, obj):

return objects, clsfields

def __init__(self) -> None:
def __new__(cls, *args, **kwargs):
out = super().__new__(cls)
out._setup()
return out

def _setup(self) -> None:
cls = type(self)
# print(f"Called Node init {cls.__qualname__:<20} {'-' * 80}")

Expand Down Expand Up @@ -309,6 +314,7 @@ def __init__(self) -> None:
if hasattr(base, "__postinit__"):
base.__postinit__(self)

def __init__(self): ...
def __preinit__(self): ...
def __postinit__(self): ...

Expand Down

0 comments on commit 64d2b9f

Please sign in to comment.