FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-95065: Argument Clinic: Pretty-print long C strings in generated code by erlend-aasland · Pull Request #107712 · python/cpython · GitHub

/ cpython Public

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

Merged
erlend-aasland merged 8 commits into
python:mainfrom
erlend-aasland:ac-deprecate-pprint-c-strings
Aug 7, 2023
Merged

gh-95065: Argument Clinic: Pretty-print long C strings in generated code#107712
erlend-aasland merged 8 commits into
python:mainfrom
erlend-aasland:ac-deprecate-pprint-c-strings

Conversation

erlend-aasland commented Aug 7, 2023
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread Tools/clinic/clinic.py Outdated
Comment thread Tools/clinic/clinic.py Outdated

Copy link
Copy Markdown
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 commented Aug 7, 2023
edited
Loading

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Member

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

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

Copy link
Copy Markdown
Contributor Author

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

Unfortunately, not so simple.

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor Author

I think 3de2378 should do the trick.

Comment thread Tools/clinic/clinic.py
Comment on lines +227 to +230
width: int = 72,
suffix: str = '',
initial_indent: int = 0,
subsequent_indent: int = 4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hm, perhaps.

Comment thread Tools/clinic/clinic.py
Comment thread Tools/clinic/clinic.py Outdated
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
erlend-aasland enabled auto-merge (squash) August 7, 2023 14:15

Copy link
Copy Markdown
Contributor Author

Thank you for the reviews!

erlend-aasland merged commit 835e388 into python:main Aug 7, 2023
erlend-aasland deleted the ac-deprecate-pprint-c-strings branch August 7, 2023 14:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL