8000 gh-113317: Argument Clinic: move C/Py identifier helpers into libclinic by erlend-aasland · Pull Request #115520 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-113317: Argument Clinic: move C/Py identifier helpers into libclinic #115520

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

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Pull in main
  • Loading branch information
erlend-aasland committed Feb 15, 2024
commit 8f9be0e1e7abd19710e36232eac6822530feef65
44 changes: 0 additions & 44 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,50 +138,6 @@ def fail(
warn_or_fail(*args, filename=filename, line_number=line_number, fail=True)


def linear_format(s: str, **kwargs: str) -> str:
"""
Perform str.format-like substitution, except:
* The strings substituted must be on lines by
themselves. (This line is the "source line".)
* If the substitution text is empty, the source line
is removed in the output.
* If the field is not recognized, the original line
is passed unmodified through to the output.
* If the substitution text is not empty:
* Each line of the substituted text is indented
by the indent of the source line.
* A newline will be added to the end.
"""
lines = []
for line in s.split('\n'):
indent, curly, trailing = line.partition('{')
if not curly:
lines.extend([line, "\n"])
continue

name, curly, trailing = trailing.partition('}')
if not curly or name not in kwargs:
lines.extend([line, "\n"])
continue

if trailing:
fail(f"Text found after {{{name}}} block marker! "
"It must be on a line by itself.")
if indent.strip():
fail(f"Non-whitespace characters found before {{{name}}} block marker! "
"It must be on a line by itself.")

value = kwargs[name]
if not value:
continue

stripped = [line.rstrip() for line in value.split("\n")]
value = textwrap.indent("\n".join(stripped), indent)
lines.extend([value, "\n"])

return "".join(lines[:-1])


class CRenderData:
def __init__(self) -> None:

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0