-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
gh-128127: add feature for ast.NodeVisitor generic_visit to return list of all return values of calls to visit_
#128128
base: main
Are you sure you want to change the base?
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
271dd8f
to
e98f3fb
Compare
e98f3fb
to
ab2537e
Compare
This will blow-up memory footprint a lot, especially for static analysis tool so I'm not very sure it should be done. A visitor pattern is essentially used for traversing nodes, dynamically dispatching to the correct method efficiently, but it's not meant to remember what has been visited by default. If such behaviour is desired, a dedicated visitor class must be implemented instead. |
There's also some usability issues. For example, currently it's OK to reuse the same visitor instance for multiple concurrent or consecutive visits, but with this change, those runs will accumulate into the same list. I'm not sure that collecting the return values of all |
I also thought about maybe this takes too much memory, and wasn't completely sure about this. Do you think I should make a new class for this feature or make tracking nodes optional(assuming this feature is still desirable)? |
|
I don't think we'll accept this in the standard library, however you can create a third-party library and publish it on pypi. |
This implementation tries to ensure that previous behaviour of visit is not disturbed. For visit's new behaviour to work, derived classes need to call supers constructor, otherwise it behaves same as before.
visit_
#128127