Skip to content

Adding PyMethod_New to stable ABI / limited API #108

Description

@NicolasT

When implementing, in some extension, a custom callable type similar to PyFunction_Type, one may want to set Py_TPFLAGS_METHOD_DESCRIPTOR in the tp_flags. In many such cases, the implementation of tp_descr_get is trivial and essentially that of PyFunction_Type:

     if (obj == Py_None || obj == NULL) {
          return Py_NewRef(func);
      }
      return PyMethod_New(func, obj);

PyMethod_New is currently not part of the stable ABI (I believe), and hence not part of the limited API. Since the functionality provided by PyMethod_Type is quite extensive, providing a local re-implementation of a similar type seems a bit wasteful (iff possible under limited API at all).

Assuming the prototype of PyMethod_New seems unlikely to change and only depends on PyObject * values, would the workgroup consider adding PyMethod_New to the stable ABI / limited API?

For reference, I believe nanobind has a local implementation of a similar type, though a cursory check seems to indicate it's less "advanced" than PyMethod_Type (e.g., it doesn't come with a __reduce__ method).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions