Support classmethod
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the proposed classmethod helper, including pybind11::cpp_function and Python's PyClassMethod_New, then compare it with the existing pybind11 binding entry points. Done means pybind11 provides a supported classmethod mechanism matching the demonstrated usage, with tests covering the resulting class attribute behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100