8000 gh-108494: Argument Clinic: fix option group for Limited C API by vstinner · Pull Request #108574 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-108494: Argument Clinic: fix option group for Limited C API #108574

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 2 commits into from
Aug 29, 2023
Merged
Changes from all commits
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
8000
Diff view
12 changes: 9 additions & 3 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,8 @@ def group_to_variable_name(group: int) -> str:
def render_option_group_parsing(
self,
f: Function,
template_dict: TemplateDict
template_dict: TemplateDict,
limited_capi: bool,
) -> None:
# positional only, grouped, optional arguments!
# can be optional on the left or right.
Expand Down Expand Up @@ -1713,7 +1714,11 @@ def render_option_group_parsing(
count_min = sys.maxsize
count_max = -1

add("switch (PyTuple_GET_SIZE(args)) {\n")
if limited_capi:
nargs = 'PyTuple_Size(args)'
else:
nargs = 'PyTuple_GET_SIZE(args)'
add(f"switch ({nargs}) {{\n")
Comment on lines +1718 to +1721
Copy link
Member

Choose a reason for hiding this comment

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

Style suggestion -- because of the f-strings needing the duplication of {, perhaps just being explicit in both cases would be worth it?

Suggested change
nargs = 'PyTuple_Size(args)'
else:
nargs = 'PyTuple_GET_SIZE(args)'
add(f"switch ({nargs}) {{\n")
add("switch (PyTuple_Size(args)) {\n")
else:
add("switch (PyTuple_GET_SIZE(args)) {\n")

for subset in permute_optional_groups(left, required, right):
count = len(subset)
count_min = min(count_min, count)
Expand Down Expand Up @@ -1870,7 +1875,8 @@ def render_function(
template_dict['unpack_max'] = str(unpack_max)

if has_option_groups:
self.render_option_group_parsing(f, template_dict)
self.render_option_group_parsing(f, template_dict,
limited_capi=clinic.limited_capi)

# buffers, not destination
for name, destination in clinic.destination_buffers.items():
Expand Down
0