Skip to content

gh-113367: Avoid redundant gotos and labels in Argument Clinic - #158284

Open
Prateek99-s wants to merge 1 commit into
python:mainfrom
Prateek99-s:clinic-redundant-gotos
Open

Prateek99-s wants to merge 1 commit into
python:mainfrom
Prateek99-s:clinic-redundant-gotos

Conversation

@Prateek99-s

@Prateek99-s Prateek99-s commented Sep 27, 2026 •

Copy link
Copy Markdown

Summary

When an Argument Clinic function has optional positional arguments and optional keyword-only arguments without any required keyword-only arguments, clinic generated gotos to `skip_optional_pos:`, which immediately performed a redundant check and second jump `if (!noptargs) goto skip_optional_kwonly;`.

### Changes
1. Tools/clinic/libclinic/parse_args.py:
   - If there are no required keyword-only arguments (`not self.min_kw_only`), gotos in the positional section jump directly to `skip_optional_kwonly`.
   - Bypasses the redundant intermediate label `skip_optional_pos:` and the unreachable check `if (!noptargs) goto skip_optional_kwonly;` at the start of the keyword-only section.
   - Preserves separate labels if required keyword-only arguments exist (`self.min_kw_only > 0`).
2. Regenerated clinic headers:
   - Regenerated all affected `.c.h` files via `Tools/clinic/clinic.py --make` (net reduction of ~288 redundant lines across 25 C modules).
3. Tests:
   - Updated golden test file `Lib/test/clinic.test.c`.
   - Verified that all 412 clinic tests pass (`./python -m test test_clinic`), as well as tests for affected modules (`test_datetime`, `test_socket`, `test_bisect`).

Avoid generating redundant gotos, the intermediate skip_optional_pos label, and the duplicate if (!noptargs) check when a function has optional positional and keyword-only arguments without required keyword-only arguments.
@python-cla-bot

python-cla-bot Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

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.

1 participant