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

Weakref unsupported in AST #81

Closed
AstraLuma opened this issue Mar 15, 2020 · 3 comments · Fixed by #82
Closed

Weakref unsupported in AST #81

AstraLuma opened this issue Mar 15, 2020 · 3 comments · Fixed by #82

Comments

@AstraLuma
Copy link
Contributor

graphql.language.ast makes extensive use of __slots__ but __weakref__ is given, breaking the weakref module.

The use of __slots__ without __weakref__ makes it very hard to track data about AST nodes in a non-leaky way.

@AstraLuma
Copy link
Contributor Author

My use case: My library does analysis of graphql queries, including figuring out the schema type of each node (for later directive finding).

The slots & no weakref situation means that I can't attach data directly to nodes, I'll keep the nodes around if I keep them in a dictionary, and I'll leak data if I use the object IDs.

@Cito
Copy link
Member

Cito commented Mar 15, 2020

Thanks for the feedback, @astronouth7303. Does it solve your problem when we add "__weakref__" to the __slots__ attribute of Node? What be the disadvantages of this change? Just a slightly higher memory consumption overall because of the additional slot, right?

@AstraLuma
Copy link
Contributor Author

Yup, that'll fix it up nice.

I think there might be a slight memory increase, something like an extra pointer per instance. I'm not intimately familiar with what __slots__ does under the hood, though, so the above is speculation. I believe the usual rules of attributes still exist (namely that the attribute doesn't exist until it's assigned to, which in this case I'm pretty sure happens on first weakref use).

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

Successfully merging a pull request may close this issue.

2 participants