gh-148981: Add color to ast.dump#148982
gh-148981: Add color to ast.dump#148982StanFromIreland wants to merge 10 commits intopython:mainfrom
ast.dump#148982Conversation
|
When you're done making the requested changes, leave the comment: |
Ok, I made I have made the requested changes; please review again |
|
I reformulate what I said in the issue: it won't be possible to add colors to the CLI only as we would get a string only, so ok for this additional parameter. However, node that there are sometimes hidden attributes in the dump, so choose another color for them as well. |
|
Actually, I don't know whether your approach is entirely fine. AST nodes can contain arbitrary strings and this can definitely mess the output. You can either (1) change how the formatted string is constructed (depending on color) [in which case you retain the color keyword] or (2) don't add a color keyword and only add it to the CLI and then colorize the entire string after it's been dumped with the regex. |
|
Note: I'm not entirely sure we can have a perfect colorization during the formatting as we use |
|
Thanks for the review Bénédikt, I changed it to add color directly in |
|
Fuzz failure is unrelated, I think something must be messing with the path. I’ll look into it. CC @sethmlarson |
hugovk
left a comment
There was a problem hiding this comment.
btw we can now remove color=True from argparse.ArgumentParser(color=True) as it's the default (and in fact could remove from other CLIs).
I recommend replacing it with formatter_class=argparse.ArgumentDefaultsHelpFormatter to also include colour defaults in the help (and remove the hardcoded defaults in help=).
I did those too. |
|
Does it make sense to support |
Hmm, we don't have a precedent, the other APIs with color support (e.g. |
|
I think it was a mistake to have color=True for unified_diff, or more generally for functions that return strings because they are actually breaking APIs that expect plain strings (possibly to render to something else afterwards that does not support colors at all) |
|
As for |
Does it make sense? No.
It makes sense if we have something like |
For example,
echo 'def f(): x = f"{1_0}"; y = True' | ./python -m ast:ast.dumpoutput #148981📚 Documentation preview 📚: https://cpython-previews--148982.org.readthedocs.build/