33from __future__ import annotations
44
55from copy import deepcopy
6- from dataclasses import asdict , dataclass , field , fields , is_dataclass
6+ from dataclasses import asdict , dataclass , field , is_dataclass
77from enum import Enum , IntEnum
88from os import getenv
99from pickle import dumps
1010from types import UnionType
11- from typing import (
12- Any ,
13- Callable ,
14- ClassVar ,
15- Iterable ,
16- Optional ,
17- Type ,
18- TypeVar ,
19- cast ,
20- get_args ,
21- get_origin ,
22- get_type_hints ,
23- )
11+ from typing import Any , Callable , ClassVar , Iterable , Optional , Type , TypeVar , cast
2412from uuid import UUID , uuid4
2513
26- from jaclang .compiler .constant import EdgeDir , T
14+ from jaclang .compiler .constant import EdgeDir
2715from jaclang .runtimelib .utils import collect_node_connections
2816
2917MANUAL_SAVE = getenv ("ENABLE_MANUAL_SAVE" ) == "true"
3018TARCH = TypeVar ("TARCH" , bound = "Architype" )
3119TANCH = TypeVar ("TANCH" , bound = "Anchor" )
3220
3321
34- def to_dataclass (cls : type [T ], data : dict [str , Any ], ** kwargs : object ) -> T :
35- """Parse dict to dataclass."""
36- hintings = get_type_hints (cls )
37- for attr in fields (cls ): # type: ignore[arg-type]
38- if target := data .get (attr .name ):
39- hint = hintings [attr .name ]
40- if is_dataclass (hint ):
41- data [attr .name ] = to_dataclass (hint , target )
42- else :
43- origin = get_origin (hint )
44- if origin == dict and isinstance (target , dict ):
45- if is_dataclass (inner_cls := get_args (hint )[- 1 ]):
46- for key , value in target .items ():
47- target [key ] = to_dataclass (inner_cls , value )
48- elif (
49- origin == list
50- and isinstance (target , list )
51- and is_dataclass (inner_cls := get_args (hint )[- 1 ])
52- ):
53- for key , value in enumerate (target ):
54- target [key ] = to_dataclass (inner_cls , value )
55- return cls (** data , ** kwargs )
56-
57-
5822class AnchorType (Enum ):
5923 """Enum For Anchor Types."""
6024
@@ -778,8 +742,6 @@ class Architype:
778742
779743 _jac_entry_funcs_ : list [DSFunc ]
780744 _jac_exit_funcs_ : list [DSFunc ]
781- __jac_classes__ : dict [str , type [Architype ]]
782- __jac_hintings__ : dict [str , type ]
783745
784746 def __init__ (self , __jac__ : Optional [Anchor ] = None ) -> None :
785747 """Create default architype."""
@@ -796,27 +758,6 @@ def __repr__(self) -> str:
796758 """Override repr for architype."""
797759 return f"{ self .__class__ .__name__ } "
798760
799- @classmethod
800- def __set_classes__ (cls ) -> dict [str , Any ]:
801- """Initialize Jac Classes."""
802- jac_classes = {}
803- for sub in cls .__subclasses__ ():
804- sub .__jac_hintings__ = get_type_hints (sub )
805- jac_classes [sub .__name__ ] = sub
806- cls .__jac_classes__ = jac_classes
807-
808- return jac_classes
809-
810- @classmethod
811- def __get_class__ (cls : type [TARCH ], name : str ) -> type [TARCH ]:
812- """Build class map from subclasses."""
813- jac_classes : dict [str , Any ] | None = getattr (cls , "__jac_classes__" , None )
814- if not jac_classes or not (jac_class := jac_classes .get (name )):
815- jac_classes = cls .__set_classes__ ()
816- jac_class = jac_classes .get (name , cls )
817-
818- return jac_class
819-
820761
821762class NodeArchitype (Architype ):
822763 """Node Architype Protocol."""
0 commit comments