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

gh-95065: Argument Clinic: Pretty-print long C strings in generated code #107712

Merged

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented Aug 7, 2023

Copy link
Member

@serhiy-storchaka serhiy-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?

Tools/clinic/clinic.py Outdated Show resolved Hide resolved
Tools/clinic/clinic.py Outdated Show resolved Hide resolved
@erlend-aasland
Copy link
Contributor Author

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
Contributor Author

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(...)
for line in wrapped:
    # add indent, add quoted line, add suffix and newline

@serhiy-storchaka
Copy link
Member

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

@erlend-aasland erlend-aasland force-pushed the ac-deprecate-pprint-c-strings branch from b2d7f3a to 68c1b1e Compare August 7, 2023 12:48
@erlend-aasland
Copy link
Contributor Author

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

Unfortunately, not so simple.

@erlend-aasland
Copy link
Contributor Author

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

@erlend-aasland
Copy link
Contributor Author

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
Contributor Author

Choose a reason for hiding this comment

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

Hm, perhaps.

Tools/clinic/clinic.py Show resolved Hide resolved
Tools/clinic/clinic.py Outdated Show resolved Hide resolved
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@erlend-aasland erlend-aasland enabled auto-merge (squash) August 7, 2023 14:15
@erlend-aasland
Copy link
Contributor Author

Thank you for the reviews!

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

Successfully merging this pull request may close these issues.

4 participants