-
Notifications
You must be signed in to change notification settings - Fork 188
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
♻️ REFACTOR: EntityAttributesMixin
-> NodeAttributes
#5442
♻️ REFACTOR: EntityAttributesMixin
-> NodeAttributes
#5442
Conversation
NodeRepositoryMixin
-> NodeRepository
EntityAttributesMixin
-> NodeAttributes
e71d94d
to
5e8f824
Compare
5e8f824
to
d815e49
Compare
d815e49
to
9e67375
Compare
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.
Thanks @chrisjsewell , just some minor things.
aiida/orm/nodes/attributes.py
Outdated
self._entity = node | ||
self._backend_entity = node.backend_entity |
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.
Any reason to keep the name entity
here when it only ever applies to a node? Would _node
and _backend_node
not be clearer?
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.
done
aiida/orm/nodes/attributes.py
Outdated
def __contains__(self, key: str) -> bool: | ||
"""Check if the node contains an attribute with the given key.""" | ||
return key in self._backend_entity.attributes |
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 addition I think? Don't think I have seen an added test for this, correct?
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've removed the method for now
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.
re-instated because there is actually a test, hence why they were failing
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.
Note @sphuber, it's my intention to look into making attributes and extras a subclass of MutableMapping
(https://docs.python.org/3/library/collections.abc.html?highlight=mutablemapping#collections-abstract-base-classes), which would actually remove this method.
But this change is just additive, i.e. is just adding extra methods and not breaking anything. So don't want to hold up this initial re-structuring with it
@@ -194,6 +200,16 @@ def base(self) -> NodeBase: | |||
"""Return the node base namespace.""" | |||
return NodeBase(self) | |||
|
|||
def _check_mutability_attributes(self, keys: Optional[List[str]] = None) -> None: # pylint: disable=unused-argument |
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.
Why do we need an explicit method for mutability of attributes? I don't think there are degrees of mutabillity are there? If it doesn't already exist, I would just have a _check_mutability
. And really, since you are calling it from outside of the class, it should be public. I know that you probably do this to keep the namespace clean, but this seems to be a fundamental property. Alternatively, put it in Node.base.check_mutability
?
I see now, this is to do with the Sealable
aspect. I also notice that you essentially fixed a bug. I think that set_attribute_many
would have been possible on sealed nodes because Sealable
didn't override that method. Same goes for delete_attribute_many
. Anyway, I don't have a better solution for this at this point, so fine to keep for now.
Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
@chrisjsewell just to let you know that tests are failing, so cannot merge yet |
You forgot to apply the |
Third times a charm 🤞 |
All tests passing @sphuber |
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.
There are still uses of the deprecated methods:
tests/tools/archive/test_complex.py::test_reexport
tests/tools/archive/test_complex.py::test_reexport
tests/tools/archive/test_complex.py::test_reexport
tests/tools/archive/test_complex.py::test_reexport
/home/runner/work/aiida-core/aiida-core/tests/tools/archive/test_complex.py:181: AiidaDeprecationWarning: `Dict.attributes` is deprecated, use `Dict.base.attributes.all` instead. (this will be removed in v3)
item['param']['*'].attributes,
tests/tools/archive/test_complex.py::test_reexport
tests/tools/archive/test_complex.py::test_reexport
tests/tools/archive/test_complex.py::test_reexport
tests/tools/archive/test_complex.py::test_reexport
/home/runner/work/aiida-core/aiida-core/tests/tools/archive/test_complex.py:186: AiidaDeprecationWarning: `CalculationNode.attributes` is deprecated, use `CalculationNode.base.attributes.all` instead. (this will be removed in v3)
item['calc']['*'].attributes,
tests/tools/archive/test_complex.py::test_reexport
tests/tools/archive/test_complex.py::test_reexport
tests/tools/archive/test_complex.py::test_reexport
tests/tools/archive/test_complex.py::test_reexport
/home/runner/work/aiida-core/aiida-core/tests/tools/archive/test_complex.py:187: AiidaDeprecationWarning: `ArrayData.attributes` is deprecated, use `ArrayData.base.attributes.all` instead. (this will be removed in v3)
item['array']['*'].attributes,
tests/tools/archive/test_simple.py::test_calc_of_structuredata
/home/runner/work/aiida-core/aiida-core/tests/tools/archive/test_simple.py:66: AiidaDeprecationWarning: `StructureData.attributes` is deprecated, use `StructureData.base.attributes.all` instead. (this will be removed in v3)
for k in node.attributes.keys():
tests/tools/archive/test_simple.py::test_calc_of_structuredata
/home/runner/work/aiida-core/aiida-core/tests/tools/archive/test_simple.py:66: AiidaDeprecationWarning: `CalcJobNode.attributes` is deprecated, use `CalcJobNode.base.attributes.all` instead. (this will be removed in v3)
for k in node.attributes.keys():
tests/tools/archive/test_specific_import.py::test_cycle_structure_data
/home/runner/work/aiida-core/aiida-core/tests/tools/archive/test_specific_import.py:124: AiidaDeprecationWarning: `CalculationNode.attributes` is deprecated, use `CalculationNode.base.attributes.all` instead. (this will be removed in v3)
assert isinstance(calculation.attributes, dict)
tests/tools/archive/test_specific_import.py::test_cycle_structure_data
/home/runner/work/aiida-core/aiida-core/tests/tools/archive/test_specific_import.py:125: AiidaDeprecationWarning: `CalculationNode.attributes` is deprecated, use `CalculationNode.base.attributes.all` instead. (this will be removed in v3)
assert len(calculation.attributes) != 0
tests/tools/groups/test_paths.py::test_walk_nodes
/home/runner/work/aiida-core/aiida-core/tests/tools/groups/test_paths.py:137: AiidaDeprecationWarning: `Data.attributes` is deprecated, use `Data.base.attributes.all` instead. (this will be removed in v3)
assert [(r.group_path.path, r.node.attributes) for r in group_path.walk_nodes()] == [('a', {'i': 1, 'j': 2})]
Would be good to fix those, then we can merge
How helpful are those deprecation warnings though 😉 |
very 👍 |
for more information, see https://pre-commit.ci
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.
Thanks @chrisjsewell good to go
Part of addressing #4976 and https://github.com/aiidateam/aiida-core/discussions/5465
Similar to #5439, it moves the node's attributes methods to a separate "namespace", in a back compatible manner, and is another step towards #4976 (comment): removing another 10 methods (i.e. #5439 + #5442, goes from 83 -> 58)
the following deprecations are made:
e.g.
Node.get_attribute
toNode.base.attributes.get
It also actually fixes a bug with the
Sealable
mixin ofProcessNode
, whereby it only overrodeset_attribute
anddelete_attribute
, to change mutability behaviour, but not any other mutation methods, likeset_attribute_many
, etc