-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom props #37
Custom props #37
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,17 +39,30 @@ | |
] | ||
|
||
|
||
CustomT = Optional[Mapping[str, Any]] | ||
RefT = Optional[str] | ||
|
||
|
||
class Node(BaseModel): | ||
""" | ||
Base impl of all state tree nodes. | ||
""" | ||
|
||
kind: KindT = Field(description="The type of this node.") | ||
params: Optional[Mapping[str, Any]] = Field(description="Optional params that are needed for this node.") | ||
additional_properties: Optional[Mapping[str, Any]] = Field( | ||
description="Optional free-style dict with custom, non-schema props." | ||
) | ||
children: Optional[list[Node]] = Field(description="Optional collection of nested child nodes.") | ||
custom: CustomT = Field(description="Custom data to store attached to this node.") | ||
ref: RefT = Field(description="Optional reference that can be used to access this node.") | ||
|
||
def __init__(self, **data): | ||
# extract `custom` value from `params` | ||
params = data.get("params", {}) | ||
if "custom" in params: | ||
data["custom"] = params.pop("custom") | ||
if "ref" in params: | ||
data["ref"] = params.pop("ref") | ||
Comment on lines
+62
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JonStargaryen @midlik Added support for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you wanted to say "Please add" instead of "Added" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, partially added it myself :) |
||
|
||
super().__init__(**data) | ||
|
||
|
||
class FormatMetadata(BaseModel): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be simpler to just include "custom" and "ref" as one of the node params? It would be defined in a params base class that all param classes would extend.
Instead of for example:
We would have:
I believe this will simplify code in
Node.__init__
andmake_params
as they won't need to treat "custom" and "ref" in any special way.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the benefit of this other than simpler params?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, you are right, this would also allow to not have ref/custom on all nodes for example if we ever don't want to support it everywhere.