mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user