-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add context argument to Port
validator method
#141
Conversation
@muhrin @greschd @chrisjsewell this is a first proposal to add a context to port validators. I made it backward compatible with a deprecation warning so people can update their validator specs. I will soon open a corresponding PR on Questions:
|
Wouldn't it be more consistent with the namespace case to pass the |
The reason is that |
Wait, isn't the
I don't think I'm familiar enough with this part of the code to have a valid opinion on this.
My comment was mostly in reply to the naming -- I wouldn't make things more complicated just because of that. |
No it is simply added as a class member, i.e. |
In general, it looks good to me and inline with what we discussed in aiidateam/aiida-quantumespresso#418 (comment) and #130 👍 Line 109 in 110c937
But reimplemented by @muhrin in daa63de, so perhaps he can remember why!? |
Actually, if the value can now only be |
Fair enough, but why plural? It will always be a single instance of a |
Well wouldn't it be |
In the case of a |
The functionality was used only by the `Port` class and it simply constructed an instance in its constructor and forwarded the property getter and setters. This unnecessary layer is removed and the functionality is directly implemented on the `Port` base class.
For normal `Port` instances, the `validator` signature changes from `validator(value)` to `validator(value, port)` where `port` is the instance of the `Port` to which the called validator is assigned. For `PortNamespace` validators the `port` argument is the instance of the port namespace itself. The `port` is especially useful in validators of namespaces because it can be used to see what ports are actually present. The expose functionality, which allows to exclude or include only certain ports can fundamentally change the ports that are present in a namespace, however, the validator remains untouced. To make the validator robust to these changes it should check if the port of interest is still present in the namespace before checking the corresponding value passed in the `values` argument.
74c419d
to
456d651
Compare
OK, I have swapped the two commits, removing the @muhrin for me this is good to go. Let me know if you are happy with this. There are two issues in |
Ok, this one is good to go. I was looking through to see why there was a |
Fixes #126
For normal
Port
instances, thevalidator
signature changes fromvalidator(value)
tovalidator(value, ctx)
wherectx
is theinstance of the
ValueSpec
to which the called validator is assigned.For
PortNamespace
validators thectx
argument is the instance of theport namespace itself.
The
ctx
is especially useful in validators of namespaces because itcan be used to see what ports are actually present. The expose
functionality, which allows to exclude or include only certain ports can
fundamentally change the ports that are present in a namespace, however,
the validator remains untouced. To make the validator robust to these
changes it should check if the port of interest is still present in the
namespace before checking the corresponding value passed in the
values
argument.