Incorrect binding when the derived class is polymorphic and the base is not
Open
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
The issue from Gitter
Reproducible example code
#include "pybind11/pybind11.h"
namespace py = pybind11;
struct BaseNonPolymorphic {
unsigned int a;
unsigned int b;
unsigned int c;
unsigned int d;
};
struct Derived : BaseNonPolymorphic {
Derived() {
a = 1;
b = 2;
c = 3;
d = 4;
};
virtual ~Derived() {};
};
PYBIND11_MODULE(test_inheritance, m) {
py::class_<BaseNonPolymorphic > base_class(m, "Base");
base_class
.def_readwrite("d", &BaseNonPolymorphic::d)
;
py::class_<Derived> derived_class(m, "Derived", base_class);
derived_class
.def(py::init<>())
;
}
import test_inheritance
derived_instance = test_inheritance.Derived()
assert derived_instance.d == 4
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 with the C++ reproducible example using pybind11/pybind11.h and the PYBIND11_MODULE entry point, then run the Python assertion against the Derived binding. Trace how the non-polymorphic base and polymorphic derived class are bound; done means derived_instance.d evaluates to 4 as shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100