Skip to content
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

Contents setter not working as expected #113

Open
peterzjx opened this issue Aug 26, 2020 · 1 comment
Open

Contents setter not working as expected #113

peterzjx opened this issue Aug 26, 2020 · 1 comment

Comments

@peterzjx
Copy link

peterzjx commented Aug 26, 2020

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.

@peterzjx
Copy link
Author

peterzjx commented Nov 1, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant