-
Notifications
You must be signed in to change notification settings - Fork 192
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 possibility to remove inputs from a builder with delattr
#4381
Comments
@sphuber does this require any discussion? In some way it feels similar to the recent changes in dict behaviour, but maybe there is a reason for the builder specifically not to allow this? If you can't think of one, I can start working on this. |
No, this should be extremely straightforward. I don't see any problems with this, just implement |
So there's one subtlety here, which I think we should be aware of but probably doesn't affect the decision on this: When deleting an input with In [34]: builder = PwCalculation.get_builder()
In [35]: builder.code = <some_code>
In [36]: del builder['code']
In [37]: builder.code # The builder has a 'code' attribute (actually, a property) that returns `None`
In [38]: del builder['code'] # Deleting a second time doesn't work
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-38-bdc7a2e3ca23> in <module>
----> 1 del builder['code']
/data/aiida/source/aiida-core/aiida/engine/processes/builder.py in __delitem__(self, item)
111
112 def __delitem__(self, item):
--> 113 self._data.__delitem__(item)
114
115 def _update(self, *args, **kwds):
KeyError: 'code'
In [39]: hasattr(builder, 'code')
Out[39]: True So when translating that to |
@greschd Nice catch. So, this is not the "correct" python behavior, right? I mean, when you |
I think it's kind of a grey area. The reason it's different here is that it's not a "normal" instance attribute, but a property. There isn't really an explicit specification of what In [2]: from urllib.request import Request
In [3]: r = Request(url='http://www.aiida.net/')
In [6]: r.full_url
Out[6]: 'http://www.aiida.net/'
In [7]: del r.full_url
In [8]: r.full_url
In [9]: del r.full_url Going by that, it's fine to return |
I guess the problem with the example that you sketch is not that we actually want to be deleting the attribute, we are just setting its value to
|
Right, I think that makes sense. Would that imply that |
Don't think so, because you could just be setting it later before submitting, even though that might not necessarily make sense.
should be just fine I think |
Yep, agreed. As I realized in my sneaky edit above, the builder state is valid even if the code is deleted. After all, a clean builder also doesn't have all required inputs. I think one could come up with a scenario where this makes sense - e.g., you have one piece of code responsible for "cleaning up" the builder, and then another one re-populating it. |
Currently, once you have a
builder
, you might want to remove an optional output (e.g. if you get a builder from aget_builder_restart
and want to drop an optional input).Currently, this is achievable by deleting an item using dictionary syntax:
However, the following syntax does not work:
I suggest to support also this syntax, since it is already possible (and 'suggested') to use builders with attribute access for setting data, thanks to the TAB-completion support (this can just proxy to the existing deletion function for dictionary items).
The text was updated successfully, but these errors were encountered: