-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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-116022: Improve repr()
of AST nodes
#117046
Conversation
Misc/NEWS.d/next/Core and Builtins/2024-03-19-22-21-22.gh-issue-116022.iyHENN.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: AN Long <[email protected]>
Co-authored-by: AN Long <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, and sorry I missed this PR!
I think your approach makes sense but there's a number of small things missing in the C code, and we need good unit test coverage for the new code.
Thanks for taking a look!
If you had a different approach in mind, I'm happy to change it. This is what makes sense to me, but maybe it's not the best way to go about it.. I've been busy with work lately, but I'll try to add more tests to the PR in the coming days :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should also be documented in the ast module (a versionchanged note saying that the repr() of AST nodes now includes the values of fields) and in the What's New for 3.13. (Or 3.14 if we don't get this ready before Tuesday.)
I moved the tests to a separate data folder and added a CLI toggle to automatically regenerate them with The advantage of snapshot testing is that we don't need to write the test cases manually - both the initial tests and whenever they need to be updated. You can just run @ambv In case you have some thoughts on this |
^ fixed the conflicts in tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking pretty good!
} | ||
|
||
if (!value_repr) { | ||
Py_DECREF(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can DECREF name and value earlier so you don't have to repeat this. Looks like value
is no longer needed after line 1602, so you could DECREF it there. name
could be DECREFed after line 1623.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I move those DECREFs up
There's some CI failure that looks like something needs to be tweaked in relation to the new file. |
Thanks for pointing that out, should be fixed now :) |
There's some CI failures related to conversion warnings, I think there are some changes landing soon around that so I'll wait for now. |
Thanks @JelleZijlstra and everyone else for reviews and help on getting this done! |
Co-authored-by: AN Long <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
closes #116022
Based on the original issue the new
repr()
has:Node(...)
body
): more than 2 items are shown as[repr(first), ..., repr(last)]
Examples (output is formatted to be more readable):
Happy to take feedback :)
repr()
of AST nodes #116022