-
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
Should Port.validate
fail if required=False
and receives None
which does not match valid_type
?
#226
Comments
@muhrin @chrisjsewell thoughts? |
Thanks Seb, I was actually just writing a response on the issue. Essentially I agree with your analysis. All of this comes down to an original choice I made which is best demonstrated with dictionaries (which input port hierarchies emulate). Essentially, should this:
be considered the same as:
i.e. should the lack of a key in a dictionary be equivalent to the key being there with a value of My instinct is that I don't remember if it's possible in plumpy to do (following from your example):
which should be To summarise, as it stands, I still prefer the original behaviour but I'm not opposed to the change. I would just caution that this assumption has certain consequences that aren't necessarily obvious and may appear in other parts of the code and so care should be taken to make sure the behaviour is consistent throughout. |
Indeed we do. We define
This actually doesn't work because In [1]: from plumpy import InputPort
In [2]: port = InputPort('test', valid_type=str, required=False)
In [3]: port.validate()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-5f493d0fc7eb> in <module>
----> 1 port.validate()
TypeError: validate() missing 1 required positional argument: 'value' Note that for the def validate(self, value=UNSPECIFIED, ...): which should then make the above example work.
This is the main point of doubt for me. Changing this would indeed most likely have potentially very subtle consequences. Not sure if it is worth it. Maybe it is best to keep the current convention and close this issue with an explicit description in the documentation. |
yeh never found a good/defacto solution to this in python
that makes sense to me |
Original issue reported in
aiida-common-workflows
:Consider the following example of a simple port that is not required and expects a string:
When we validate
None
as a value, we hit the validation error, just as in the EOS workchain. Except thatNone
should be a perfectly legal value if the port is optional. It seems weird to raise for this. The only reason I can think off to keep the current behavior is that it might be necessary to have an optional port but where an explicitNone
value is incorrect and so ifNone
is passed explicitly (instead of the input being omitted entirely) you want the port to raise. But I am wondering if this is not an edge-case and in that case the develop should simply explicitly check forNone
in a validator or the process body and ignore it.The text was updated successfully, but these errors were encountered: