-
Notifications
You must be signed in to change notification settings - Fork 40
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
Added newer DefaultTraversal rules to align with V3 sharp connectors #367
base: v3-dev
Are you sure you want to change the base?
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from specklepy.objects.base import Base | ||
from specklepy.objects.graph_traversal.traversal import GraphTraversal, TraversalRule | ||
|
||
DISPLAY_VALUE_PROPERTY_ALIASES = {"displayValue", "@displayValue"} | ||
ELEMENTS_PROPERTY_ALIASES = {"elements", "@elements"} | ||
|
||
|
||
def has_display_value(x: Base): | ||
return any(hasattr(x, alias) for alias in DISPLAY_VALUE_PROPERTY_ALIASES) | ||
|
||
|
||
def create_default_traversal_function() -> GraphTraversal: | ||
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. a test missing 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. Yes we are missing a test for this... I'm not sure we really need one since its just a factory function for traversal rules which are tested... |
||
""" | ||
Traversal func for traversing the root object of a Speckle Model | ||
""" | ||
|
||
convertible_rule = TraversalRule( | ||
[lambda b: b.speckle_type != "Base", has_display_value], | ||
lambda _: ELEMENTS_PROPERTY_ALIASES, | ||
) | ||
|
||
default_rule = TraversalRule( | ||
[lambda _: True], | ||
# NOTE: Unlike the C# implementation, this does not ignore Obsolete members | ||
lambda o: o.get_member_names(), | ||
False, | ||
) | ||
|
||
return GraphTraversal([convertible_rule, default_rule]) |
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 is the advantage of creating separate variables and methods instead of putting it as properties and @ staticmethods of new class DefaultTraversal?
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.
No reason... generally I haven't bothered with all static classes before in python...
if you'd prefer it I can do just that.