From annotated functions to meshes #55
thorwhalen
started this conversation in
Ideas
Replies: 2 comments
-
See some working code to (1) create protocols dynamically from callable annotations and (2) create a scaffold (generated code string) from callable annotations in the annotations_to_meshes module |
Beta Was this translation helpful? Give feedback.
0 replies
-
import i2
from meshed.scrap.annotations_to_meshes import (
func_types_to_scaffold,
func_types_to_protocol
)
GroupsProtocol = func_types_to_protocol(Groups.__annotations__)
groups_scaffold_str = func_types_to_scaffold(Groups.__annotations__) See that i2.Sig(GroupsProtocol.add_item_to_group)
# <Sig (self, item: __main__.Item, group: __main__.Group) -> Any> print(groups_scaffold_str)
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Consider the code below that is meant to express the interface of a
Groups
class via the methods it contains, as well as their annotations.The
Groups
class above, or rather, just the annotated methods it holds (and it's really the only role of thatGroups
class: To hold empty annotated methods) is sufficient information to define a protocol:or a dataclass with the same interface, or some mesh/dag that would hook the methods/functions up according to their annotations.
For example, we'd have a function:
Beta Was this translation helpful? Give feedback.
All reactions