Skip to content

Use of argument clinic like parsing and METH_FASTCALL support in extension modules #83528

Open

Description

@seberg
mannequin
BPO 39347
Nosy @larryhastings, @seberg

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-01-15.21:03:38.635>
labels = ['type-feature', 'expert-argument-clinic']
title = 'Use of argument clinic like parsing and `METH_FASTCALL` support in extension modules'
updated_at = <Date 2020-01-15.21:03:38.635>
user = 'https://github.com/seberg'

bugs.python.org fields:

activity = <Date 2020-01-15.21:03:38.635>
actor = 'seberg'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Argument Clinic']
creation = <Date 2020-01-15.21:03:38.635>
creator = 'seberg'
dependencies = []
files = []
hgrepos = []
issue_num = 39347
keywords = []
message_count = 1.0
messages = ['360073']
nosy_count = 2.0
nosy_names = ['larry', 'seberg']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue39347'
versions = []

Activity

  1. seberg commented on Jan 15, 2020

    sebergmannequin
    MannequinAuthor

    This is mainly an information request, so sorry if its a bit besides the point (I do not mind if you just close it). But it seemed a bit too specific to get answers in most places...
    In Python you use argument clinic, which supports METH_FASTCALL, that seems pretty awesome.

    For extension modules, I am not sure that argument clinic is a straight forward choice, since it probably generates code specific to a single Python version and also using, while we need to support multiple versions (including versions that do not support METH_FASTCALL.

    So the question would be if there is some idea for providing such C-API, or for example exposing _PyArg_UnpackKeywords (which is at the heart of kwarg parsing).

    My use-case is that some NumPy functions do have a nice speedup when using METH_FASTCALL and better argument clinic style faster arg-parsing. Which is why, looking at these things, I practically reimplemented a slightly dumbed down version of PyArg_ParseTupleAndKeywords working much like argument clinic (except less smart and only using macros and no code generation).

    That seems viable, but also feels a bit wrong, so I am curious if there may be a better solution or whether it would be plausible to expose _PyArg_UnpackKeywords to reduce code duplication. (although I suppose due to old python version support that would effectively take years)

    For completeness, my code in question is here: numpy/numpy#15269 with the actual usage pattern being:

    static PyObject *my_method(PyObject *self, NPY_ARGUMENTS_DEF)
    {
        NPY_PREPARE_ARGPARSER;
        PyObject *argument1;
        int argument2 = -1;
        if (!npy_parse_arguments("method", 1, -1, NPY_ARGUMENTS_PASS),
                    "argument1", NULL, &argument1,
                    "argument2", &PyArray_PythonPyIntFromInt, &argument2,
                    NULL, NULL, NULL) {
            return NULL;
        }
    }
  2. transferred this issue fromon Apr 10, 2022
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