GeezerVison is showing github.com — Inconsistent behaviour when stripping bytestrings via CliRunner · Issue #334 · pallets/click
Inconsistent behaviour when stripping bytestrings via CliRunner #334Labels docsUpdates to documentation, readme, docstrings, typos DescriptionCliRunner seems to strip bold ansi escape sequences from .output on python2, but they're present on python3.
The doc says color escape codes are removes, but does not mention bold codes. I'm not sure if they're meant to be kept or not, but the behaviour should be consistent across python versions. Activityuntitaker commented on May 2, 2015 Hmm, this works on both Python versions though:
assert strip_ansi(style('lol', bold=True)) == 'lol'
untitaker commented on May 2, 2015 The bug seems to be that Click doesn't do any colorcode stripping with echo(b'...') on Python 3. untitaker commented on May 2, 2015 Reading through the code, it seems that Click intentionally does not do any code-stripping when the input is bytes. WhyNotHugo commented on May 2, 2015
Why does this example use echo() instead of the regular print() function? The answer to this question is that Click attempts to support both Python 2 and Python 3 the same way and to be very robust even when the environment is misconfigured.
source
Looks it's a bug, since the doc states that this sort of discrepancy is exactly what they intend to fix. untitaker commented on May 2, 2015 WhyNotHugo commented on May 2, 2015 This isn't the issue in my case anyway. The content I'm printing is unicode on python2 and str on python3.
What you describe may be true, but it's still a separate issue. untitaker commented on May 2, 2015 untitaker commented on May 2, 2015 WhyNotHugo commented on May 2, 2015 Oh. My check was in the wrong place, I failed to notice that.
Ok, my issue seems to have been a non-issue and bad testing (twice) on my behalf.
I'll leave this open for the documentation fix you mentioned. untitaker commented on May 2, 2015 I'm definetly not sure if Click's current behavior is desirable at all though (since it's hard to debug why click didn't rip out escape sequences in this particular case), even though I apprechiate Click's careful approach to encodings. changed the title [-]Inconsistent behaviour when stripping bold via CliRunner[/-] [+]Inconsistent behaviour when stripping bytestrings via CliRunner[/+] on Jun 18, 2015mitsuhiko commented on Jul 19, 2015 Click does not strip colors from bytes, buffer or bytearray on any platform. On Python 2 because we cannot differ str and unicode stripping might happen with quasi bytes there. I do not want to break this behavior because otherwise you cannot echo binary data safely to the terminal.
Why do you need to strip ansi codes on byte data? untitaker commented on Jul 19, 2015 IIRC we're echoing bytes (when it should be unicode) in some rather old software that was recently ported to be a 2-and-3 polyglot. I think that string type was the wrong choice, but changing our string model will take a lot of time. jcrotts commented on May 15, 2018 locked as resolved and limited conversation to collaborators on Nov 13, 2020
MetadataMetadatadocsUpdates to documentation, readme, docstrings, typos DevelopmentNo branches or pull requestsIssue actions
|