Making ElementList a "view" into the model #176
Wuestengecko
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The current behavior of model object properties that return lists is very unintuitive. Normally, in the following code block, you would expect that
funcs_a is funcs_b
would beTrue
, or if not, that they are two proxies that share the same underlying data structures. However, that is not the case:This can lead to some hard to diagnose issues. For example, when entering just
funcs_a[0]
in the REPL prompt to display it, you get an exception now.To alleviate this issue and make behavior more consistent with what an experienced Python developer would expect, I therefore propose to make ElementList classes a "view" into the model. This means that, instead of making a list of references to XML elements of interest and carrying that around, they only hold a reference to the "parent" element (i.e. the container), and only when actually accessed will they go through the XML structures and find the elements to act on.
This would also mirror the behavior of other properties of
GenericElement
subclasses, which forward every access to the XML tree directly:I do know of some current test cases that rely on this unintuitive behavior, but it should be easy to fix them after these changes.
Inspired by a comment on a recent PR review. Summoning @ewuerger, the author of that comment.
Beta Was this translation helpful? Give feedback.
All reactions