Skip to content
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

Allow the definition of None as default in process functions #2582

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Mar 6, 2019

Fixes #1210

It was impossible to define a process function with a keyword argument
that had None as default, because the dynamically created ports always
only specified orm.Data as valid types. So the validation of the
default value would fail during the spec definition. Here we detect if
None is passed as the default in the function signature, in which case
we define the tuple of orm.Data and type(None) to be a valid type.
Note that we need to use type(None) because the port validation later
on will call isinstance(input, valid_types) which will not work if one
of the values in valid_types is simply None.

The Process._setup_inputs had to be adjusted to skip values of None
because they cannot be linked to obviously but they can now potentially
be passed as inputs to a Process.

@sphuber sphuber requested a review from giovannipizzi March 6, 2019 19:13
@coveralls
Copy link

coveralls commented Mar 7, 2019

Coverage Status

Coverage decreased (-3.5%) to 66.553% when pulling af8ae34 on sphuber:fix_1210_process_functions_allow_none_default into 838c1dd on aiidateam:provenance_redesign.

It was impossible to define a process function with a keyword argument
that had `None` as default, because the dynamically created ports always
only specified `orm.Data` as valid types. So the validation of the
default value would fail during the spec definition. Here we detect if
`None` is passed as the default in the function signature, in which case
we define the tuple of `orm.Data` and `type(None)` to be a valid type.
Note that we need to use `type(None)` because the port validation later
on will call `isinstance(input, valid_types)` which will not work if one
of the values in `valid_types` is simply `None`.

The `Process._setup_inputs` had to be adjusted to skip values of `None`
because they cannot be linked to obviously but they can now potentially
be passed as inputs to a `Process`.
@sphuber sphuber force-pushed the fix_1210_process_functions_allow_none_default branch from 8b19800 to af8ae34 Compare March 7, 2019 01:11
@sphuber sphuber merged commit e64a607 into aiidateam:provenance_redesign Mar 7, 2019
@sphuber sphuber deleted the fix_1210_process_functions_allow_none_default branch March 7, 2019 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants