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

@@ -80,6 +80,24 @@ def test_properties():
assert instance.def_property == 3
def test_copy_method():
"""Issue #443: calling copied methods fails in Python 3"""
from pybind11_tests import ExampleMandA
ExampleMandA.add2c = ExampleMandA.add2
ExampleMandA.add2d = ExampleMandA.add2b
a = ExampleMandA(123)
assert a.value == 123
a.add2(ExampleMandA(-100))
assert a.value == 23
a.add2b(ExampleMandA(20))
assert a.value == 43
a.add2c(ExampleMandA(6))
assert a.value == 49
a.add2d(ExampleMandA(-7))
assert a.value == 42
def test_static_properties():
from pybind11_tests import TestProperties as Type