From f00628dae015bd142b587757bd38e9430a15e42c Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Fri, 6 Mar 2026 13:36:32 +0100 Subject: [PATCH 1/2] [cppyy] fix: aliasing of TemplateProxy Fixes: #21405 --- .../cppyy/CPyCppyy/src/TemplateProxy.cxx | 4 +--- .../pyroot/cppyy/cppyy/test/test_templates.py | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) 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..2df94856c67d0 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: From 8f2199427a8f10768ec1f5995b6b07a673072a08 Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Fri, 6 Mar 2026 14:05:58 +0100 Subject: [PATCH 2/2] Use C++ types in template arguments Co-authored-by: Vincenzo Eduardo Padulano --- bindings/pyroot/cppyy/cppyy/test/test_templates.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/pyroot/cppyy/cppyy/test/test_templates.py b/bindings/pyroot/cppyy/cppyy/test/test_templates.py index 2df94856c67d0..16d356d895320 100644 --- a/bindings/pyroot/cppyy/cppyy/test/test_templates.py +++ b/bindings/pyroot/cppyy/cppyy/test/test_templates.py @@ -1221,12 +1221,12 @@ def test37_deleted_alias_of_template_proxy(self): PyA = cppyy.gbl.PyA PyA.getter = PyA.get - assert PyA().get[int]() == -1 - assert PyA().getter[int]() == -1 + assert PyA().get["int"]() == -1 + assert PyA().getter["int"]() == -1 PyA.get = None - assert PyA().getter[float]() == -1.0 + assert PyA().getter["float"]() == -1.0 class TestTEMPLATED_TYPEDEFS: