Don't let PyInstanceMethod hide itself

Python 3's `PyInstanceMethod_Type` hides itself via its `tp_descr_get`,
which prevents aliasing methods via `cls.attr("m2") = cls.attr("m1")`:
instead the `tp_descr_get` returns a plain function, when called on a
class, or a `PyMethod`, when called on an instance.  Override that
behaviour for pybind11 types with a special bypass for
`PyInstanceMethod_Types`.
This commit is contained in:
Jason Rhinelander
2017-04-16 20:30:52 -04:00
parent a7f704b39b
commit 0a90b2db71
5 changed files with 50 additions and 6 deletions

View File

@@ -163,8 +163,8 @@ public:
class NotRegistered {};
test_initializer methods_and_attributes([](py::module &m) {
py::class_<ExampleMandA>(m, "ExampleMandA")
.def(py::init<>())
py::class_<ExampleMandA> emna(m, "ExampleMandA");
emna.def(py::init<>())
.def(py::init<int>())
.def(py::init<const ExampleMandA&>())
.def("add1", &ExampleMandA::add1)
@@ -222,6 +222,9 @@ test_initializer methods_and_attributes([](py::module &m) {
.def("__str__", &ExampleMandA::toString)
.def_readwrite("value", &ExampleMandA::value);
// Issue #443: can't call copied methods in Python 3
emna.attr("add2b") = emna.attr("add2");
py::class_<TestProperties>(m, "TestProperties")
.def(py::init<>())
.def_readonly("def_readonly", &TestProperties::value)