-
Notifications
You must be signed in to change notification settings - Fork 85
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
Wrap single observer to a separate expression #1093
Conversation
traits/observers/expression.py
Outdated
|
||
@_IExpression.register |
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.
Again, nothing does issubclass
or isinstance
check. The registeration is unused. The registration is only here for code readability and discovery (e.g. it is easier to see what implement the interface).
Please can you give some examples of how a user might use |
Sure. A user will typically create an instance of The Then they can extend it using the instance methods on With that, I don't expect |
Right, but we're specifically making I don't think we actually need the |
traits/observers/expression.py
Outdated
|
||
|
||
def _create_graphs(expression, graphs=None): | ||
""" Create ObserverGraphs from a given expression. | ||
@_IExpression.register |
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.
I think we should be able to get rid of this class entirely.
Ah, you are asking about "using" the expression. I am sorry, I misunderstood your question earlier.
Alternatively we could just let |
Yes, I think this is the way to go. |
Currently, the user manual can just point to this While experienced developers can understand interfaces and therefore the |
I think the documentation concerns are secondary here. We should start with a simple, clean object structure, and then we can figure out how to best document it. Complicating the code to simplify the docs would be counterproductive. The way I'd do this would be to have an |
In case it's not clear what I mean, I made an example PR in #1094 to demonstrate; it's not a huge step away from the existing code. (Note that I didn't do any renaming: just trying to communicate the shape of the suggested changes, not trying to get all the details right.) |
No problem. I understand exactly what you meant, and have made the exact same changes you have in #1094 (to the point they are identical). Would you like me to push those changes here from your PR? |
No, ignore my PR. I'll close it. :-) |
@@ -25,25 +27,8 @@ class Expression: | |||
``HasTraits.observe`` method or the ``observe`` decorator. | |||
|
|||
An Expression is typically created using one of the top-level functions | |||
provided in this module, e.g.``trait``. | |||
provided in this module, e.g. ``trait``. |
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.
Drive-by: Without the space Sphinx refuses to display trait
as code.
Thank you for diving in though. Much appreciated. |
traits/observers/expression.py
Outdated
new = Expression() | ||
new._prior_expression = _ParallelExpression([self, expression]) | ||
return new | ||
return self |
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.
Could we drop this branch? Is it required for correctness, or is it more for optimization?
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.
(And if it's required for correctness, what happens with something like expr1 | expr2 | expr1
?)
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.
This is an optimization and yes we can drop it.
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.
LVGTM. One outstanding minor question / comment.
Closes #1076
This PR moves the construction of a single observer to a separate expression object.
Expression
remains to be user-facing: it aims at providing a user-friendly interface, e.g. instance methods for composing expressions.The internal expression objects are hidden from the user, and all implement a common interface called
_IExpression
. (That interface is rather basic at the moment). Despite the name,Expression
is not an instance of_IExpression
. An alternative naming suggestion (for either renamingExpression
or renaming_IExpression
is very welcome).Checklist
Update API reference (docs/source/traits_api_reference
)Update User manual (docs/source/traits_user_manual
)Update type annotation hints intraits-stubs