GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||
GeezerVison is showing github.com — gh-148981: Add color to `ast.dump` by StanFromIreland · Pull Request #148982 · python/cpython Conversation
|
| Before | After |
|---|---|
|
|
📚 Documentation preview 📚: https://cpython-previews--148982.org.readthedocs.build/
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This will break people who want to retain a string (ast.dump returns a string, it doesn't print something). Please don't do this but only do it for the CLI.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
When you're done making the requested changes, leave the comment: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Ok, I made I have made the requested changes; please review again |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Note: I'm not entirely sure we can have a perfect colorization during the formatting as we use |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks for the review Bénédikt, I changed it to add color directly in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Fuzz failure is unrelated, I think something must be messing with the path. I’ll look into it. CC @sethmlarson |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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=).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I did those too. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Does it make sense to support |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Hmm, we don't have a precedent, the other APIs with color support (e.g. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
As for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Does it make sense? No.
It makes sense if we have something like |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks all for the reviews! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.