diff --git a/bindings/pyroot/cppyy/CPyCppyy/src/TemplateProxy.cxx b/bindings/pyroot/cppyy/CPyCppyy/src/TemplateProxy.cxx index 9a9664c0d9a23..207cec90dbd0e 100644 --- a/bindings/pyroot/cppyy/CPyCppyy/src/TemplateProxy.cxx +++ b/bindings/pyroot/cppyy/CPyCppyy/src/TemplateProxy.cxx @@ -231,9 +231,7 @@ PyObject* TemplateProxy::Instantiate(const std::string& fname, if (pyol && !bIsCppOL && !TemplateProxy_Check(pyol)) { // unknown object ... leave well alone Py_DECREF(pyol); - Py_DECREF(pycachename); - Py_DECREF(dct); - return nullptr; + pyol = nullptr; } // find the full name if the requested one was partial diff --git a/bindings/pyroot/cppyy/cppyy/test/test_templates.py b/bindings/pyroot/cppyy/cppyy/test/test_templates.py index 7c2ea9bdfb53a..16d356d895320 100644 --- a/bindings/pyroot/cppyy/cppyy/test/test_templates.py +++ b/bindings/pyroot/cppyy/cppyy/test/test_templates.py @@ -1206,6 +1206,27 @@ def test36_constructor_implicit_conversion(self): a = ns.S(1, 2) assert a.m_a == 1 + + def test37_deleted_alias_of_template_proxy(self): + """Alias TemplateProxy and set None to orginal""" + import cppyy + + cppyy.cppdef(r""" + struct PyA { + template + T get() { return (T)-1; } + }; + """) + + PyA = cppyy.gbl.PyA + PyA.getter = PyA.get + + assert PyA().get["int"]() == -1 + assert PyA().getter["int"]() == -1 + + PyA.get = None + + assert PyA().getter["float"]() == -1.0 class TestTEMPLATED_TYPEDEFS: