Skip to content
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

Closed
cjerdonek opened this issue Jul 29, 2012 · 4 comments
Closed

textwrap.wrap expand_tabs does not behave as expected #59697

cjerdonek opened this issue Jul 29, 2012 · 4 comments

Comments

@cjerdonek
Copy link
Member

BPO 15492
Nosy @bitdancer, @cjerdonek

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:

assignee = None
closed_at = <Date 2012-08-04.19:24:10.882>
created_at = <Date 2012-07-29.21:11:56.535>
labels = ['invalid']
title = 'textwrap.wrap expand_tabs does not behave as expected'
updated_at = <Date 2012-08-06.01:43:54.233>
user = 'https://github.com/cjerdonek'

bugs.python.org fields:

activity = <Date 2012-08-06.01:43:54.233>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2012-08-04.19:24:10.882>
closer = 'r.david.murray'
components = []
creation = <Date 2012-07-29.21:11:56.535>
creator = 'chris.jerdonek'
dependencies = []
files = []
hgrepos = []
issue_num = 15492
keywords = []
message_count = 4.0
messages = ['166815', '167334', '167506', '167530']
nosy_count = 2.0
nosy_names = ['r.david.murray', 'chris.jerdonek']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue15492'
versions = []

@cjerdonek
Copy link
Member Author

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:
'a b'
'a b'

One would expect tab expansion to occur after (or while) wrapping, so that tab stops line up in the wrapped output.

@bitdancer
Copy link
Member

I think that expanding them before wrapping is correct. Any lining up would be true only for the original unwrapped input text.

@cjerdonek
Copy link
Member Author

I didn't have a chance to respond before you closed this issue. I will add more information later if that is okay. :)

@bitdancer
Copy link
Member

Sure. If you convince me we can reopen the issue :)

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants