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-145217: Add colour to `pprint` output by hugovk · Pull Request #145218 · python/cpython Conversation
|
| self._expand = bool(expand) | ||
| self._sort_dicts = sort_dicts | ||
| self._underscore_numbers = underscore_numbers | ||
| self._color = color |
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.
Shall we add a bool(color) conversion just as a few lines above?
self._compact = bool(compact) self._expand = bool(expand)
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.
Sure, can do, but not sure if it's necessary?
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.
Do we have explicit test for color=True and can_colorize=False? It's an end to end test.
something like
obj = {"key": "value"} stream = io.StringIO() # color=True should not produce no ANSI codes for streams # that do not support color pprint.pprint(obj, stream=stream, color=True) result = stream.getvalue() self.assertNotIn("\x1b[", result)
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.
Co-authored-by: sunmy2019 <[email protected]>
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: sunmy2019 <[email protected]>
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Documentation build overview
105 files changed ·
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I agree with this. But thinking further, our current highlighting logic relies on So, instead of special-casing Probe the text with tokenize first, No blacklist needed, no half-highlighted output. What do you think? def _colorize_output(text):
"""Apply syntax highlighting."""
- if "\x1b[" in text:
- # If the text already contains ANSI escape sequences
- # (for example, from a custom __repr__),
- # return as-is to avoid breaking their color.
+ # Probe: if the text cannot be fully tokenized, fall back to plain text
+ # to avoid the "half-highlighted" problem.
+ try:
+ list(tokenize.generate_tokens(_StringIO(text).readline))
+ except (SyntaxError, tokenize.TokenError):
return text
colors = list(gen_colors(text))
chars, _ = disp_str(text, colors=colors, force_color=True, escape=False)
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Could do, although that'd mean we're potentially doing |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
If that matters, we could modify the latter to raise errors (rather than catch them) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think I'll leave it like this, unless others also want to suggest something. We can always fix it later if needed. Thanks for the review! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Updated to skip those. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
That's inconsistent when nested: Would it be possible to highlight as things are being formatted, while the structure is still available? I doubt post-processing can be done reliably. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hmm, the root issue is that I'm personally fine with the current version or the previous, but also fine in skipping this for 3.15 and doing it properly for 3.16 (or just closing :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yeah. That guess might not be right; let's resist the temptation. In 3.16 a pprint refactor might be needed anyway, for PEP-813. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 90 days with no activity. |
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.