Add support for namespaced attributes in DynamicAttributes
Add support for namespaced attributes in DynamicAttribute
with a recursive approach (a DynamicAttribute
can have an attribute of type DynamicAttribute
). Usage example (both syntaxes are correct):
attrs.get_attr("mem.data.b")
attrs.get_attr("mem").get_attr("data").get_attr("b")
This is a preliminary work in order to introduce a general mechanism for specifiyng backend and export attributes.
-
Needs more tests in Python. -
Use snake convention for all attributes naming in C++ and Python. -
Solve #142 (closed)
Merge request reports
Activity
requested review from @cmoineau and @pineapple
assigned to @olivierbichler
added Feature 🚀 label
mentioned in issue #144 (closed)
reset approvals from @cmoineau by pushing to the branch
added 1 commit
- 74b27718 - Removed attribute naming convention change between C++ and Python and use snake everywhere
added Refactoring🎨 label
added 6 commits
-
d6be877b...b9f2c952 - 5 commits from branch
dev
- 0f22b49a - Merge branch 'dev' into attr_ns
-
d6be877b...b9f2c952 - 5 commits from branch
Does it solve:
import aidge_core as ai op = ai.GenericOperatorOp("any_type", 1,0,1) print(op.attr.something) # get_attr(): attribute "something" not found # How to set sub-attributes? With DynamicAttributes? op.attr.something = ai.DynamicAttributes() print(op.attr.something) # AttrDict({'something': AttrDict({})}) op.attr.something.arg1 = 4 print(op.attr.something.arg1) # AttrDict({'something': AttrDict({'arg1': 4})}) op.attr.another_thing.arg = 44 # auto create the namespace another_thing print(op.attr.another_thing.arg) # AttrDict({'something': AttrDict({'arg1': 4}), 'another_thing': AttrDict({'arg': 44})})
I am not sure that handling the last case is a good idea (auto create the namespace). There is no way with this syntax to differentiate a namespace and an attribute. With
op.attr.another_thing.arg
, firstop.attr.another_thing
is called, which at this point could be a namespace or an attribute. Handling auto creation of the namespace would imply that for any non existant attribute, we infer that what the user wants is a namespace, which is obviously not necessarily the case. It could be a typo from the user, or that the user really wants an attribute but it does not exist!@pineapple Except for my last comment, the rest is OK (I added the default constructor for binding of
DynamicAttributes
). I am in favor of not making creation of namespace automatic, thus requiring the user to first set a namespace withop.attr.something = ai.DynamicAttributes()
.added 1 commit
- f3c213c7 - Fix issue that may be related to #142 (closed)
added 10 commits
-
f3c213c7...786bd2ae - 9 commits from branch
dev
- ac463907 - Merge branch 'dev' into attr_ns
-
f3c213c7...786bd2ae - 9 commits from branch
mentioned in commit f4c537de
mentioned in issue #153 (closed)