alvinwan/TexSoup

Contents setter not working as expected

peterzjx opened this issue · 1 comments

soup = TexSoup.TexSoup(r'\a{b}{c}{d}')
soup.a.contents = ['x', 'y', 'z']

gives

soup.a.contents

['b', 'c', 'd', 'x', 'y', 'z']

Also, soup.a.args[0].contents[0] = 'x' works in 0.2.0 but not in the latest version.

Directly setting soup.a.args[0] allows the right hand side to be various types, such as text or TexNode without error, but when calling contents later one would get maximum recursion depth exceeded error in iteration of descendants.

What I would like to achieve, is an extension of the current replace feature. In the case parent not having children, it will go through parent.args to find the node and replace it. However in the case where args[0] has two or more contents, not being able to change in-place would break the DFS iteration outside.

After some investigation it seems to be a common issue for python getter/setter wrapper, as the grammar .contents[0] = calls the getter of contents instead. Workaround involves accessing the internal .contents_ which is not very elegant.