Skip to content

Argument Clinic: inline the parsing code of optional groups #155373

Closed

Description

@serhiy-storchaka

Optional groups are the last parsing method in Argument Clinic which still calls the runtime parser: it generates one PyArg_ParseTuple() call per number of arguments, in a big switch.

The code of the converters can be inlined, as in all other methods, with every argument parsed once. For _curses.window.addch([y, x,] ch, [attr]) the four PyArg_ParseTuple() calls become:

    if (nargs >= 3) {
        y = PyLong_AsInt(args[0]);
        ...
        offset += 2;
        group_left_1 = 1;
    }
    ch = args[offset];
    if (nargs == 2 || nargs == 4) {
        if (!attr_converter(args[nargs - 1], &attr)) {
            goto exit;
        }
        group_right_1 = 1;
    }

This also allows using the fastcall convention, except for constructors and other functions which need a tuple.

Errors for a wrong type of an argument become the same as in other functions, because they are now reported by the converter.

Linked PRs

Activity

  1. Sumitha007 commented on Aug 8, 2026

    @Sumitha007

    Hi, I'd like to take a look at this issue and investigate a possible implementation. I'll first trace the current optional-group parsing/code generation and see how the existing converter machinery can be reused. If there are no concerns, I'd be happy to work on this.

  2. added a commit that references this issue on Aug 23, 2026
  3. added a commit that references this issue on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions