Skip to content

Conversation

@erlend-aasland
Copy link
Contributor

@erlend-aaslanderlend-aasland commented Aug 7, 2023

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not textwrap.wrap(replace_whitespace=False, drop_whitespace=False) be used here?

@erlend-aasland
Copy link
ContributorAuthor

Could not textwrap.wrap(replace_whitespace=False, drop_whitespace=False) be used here?

Perhaps. I experimented a little bit with textwrap.TextWrapper but it does not support custom suffix like line continuation characters.

@erlend-aasland
Copy link
ContributorAuthor

erlend-aasland commented Aug 7, 2023

A simpler approach could be to use textwrap, then split("\n") and prepend/append the needed quotes and continuation:

wrapped=textwrap.wrap(...) forlineinwrapped: # add indent, add quoted line, add suffix and newline

@serhiy-storchaka
Copy link
Member

prefix + separator.join(textwrap.wrap(...)) + suffix

@erlend-aaslanderlend-aaslandforce-pushed the ac-deprecate-pprint-c-strings branch from b2d7f3a to 68c1b1eCompareAugust 7, 2023 12:48
@erlend-aasland
Copy link
ContributorAuthor

prefix + separator.join(textwrap.wrap(...)) + suffix

Unfortunately, not so simple.

@erlend-aasland
Copy link
ContributorAuthor

For example, we don't want the suffix to be applied to the last line.

@erlend-aasland
Copy link
ContributorAuthor

I think 3de2378 should do the trick.

Comment on lines +227 to +230
width: int=72,
suffix: str='',
initial_indent: int=0,
subsequent_indent: int=4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems all call sites specify a value for the subsequent_indent parameter. Maybe it should be required, instead of optional?

Suggested change
width: int=72,
suffix: str='',
initial_indent: int=0,
subsequent_indent: int=4
subsequent_indent: int,
width: int=72,
suffix: str='',
initial_indent: int=0,

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, perhaps.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@erlend-aaslanderlend-aasland enabled auto-merge (squash) August 7, 2023 14:15
@erlend-aasland
Copy link
ContributorAuthor

Thank you for the reviews!

@erlend-aaslanderlend-aasland merged commit 835e388 into python:mainAug 7, 2023
@erlend-aaslanderlend-aasland deleted the ac-deprecate-pprint-c-strings branch August 7, 2023 14:41
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@erlend-aasland@serhiy-storchaka@AlexWaygood@bedevere-bot