Skip to content

Support classmethod #1693

Open
Open
@asadchev

Description

@asadchev

I have a workaround to create classmethods in PyBind.

  template<class Func, typename ... Args>
  pybind11::object classmethod(Func f, Args ... args) {
    pybind11::object cf = pybind11::cpp_function(f, args...);
    return pybind11::object(PyClassMethod_New(cf.ptr()), true);
  }

used like this

void foo(py::object cls, ...);
cls.attr("foo") = classmethod(&foo);

Be useful to have such mechanism in pybind proper

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions