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

Skip to content

gh-113317: Argument Clinic: move linear_format into libclinic #115518

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
Next Next commit
Blacken
  • Loading branch information
erlend-aasland committed Feb 15, 2024
commit f14b9fc2557da323c0f265a7ad2d57f104a9eff9
19 changes: 11 additions & 8 deletions Tools/clinic/libclinic/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,27 @@ def linear_format(text: str, **kwargs: str) -> str:
* A newline will be added to the end.
"""
lines = []
for line in text.split('\n'):
indent, curly, trailing = line.partition('{')
for line in text.split("\n"):
indent, curly, trailing = line.partition("{")
if not curly:
lines.extend([line, "\n"])
continue

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

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

value = kwargs[name]
if not value:
Expand Down
0