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
textwrap.wrap expand_tabs does not behave as expected #59697
Comments
While working on bpo-1859, I noticed that textwrap.wrap()'s tab expansion does not seem to behave sensibly. In particular, the documentation says, "If expand_tabs is true, then all tab characters in text will be expanded to zero or more spaces, *depending on the current column* and the given tab size." The problem is that tab expansion is done as the first stage (and in particular, before wrapping), which means that "the current column" is no longer current after wrapping. This leads to results like-- from textwrap import wrap
text = ("a\tb "
"a\tb")
lines = wrap(text, width=5, tabsize=4)
for line in lines:
print(repr(line)) Output: One would expect tab expansion to occur after (or while) wrapping, so that tab stops line up in the wrapped output. |
I think that expanding them before wrapping is correct. Any lining up would be true only for the original unwrapped input text. |
I didn't have a chance to respond before you closed this issue. I will add more information later if that is okay. :) |
Sure. If you convince me we can reopen the issue :) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: