Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions bindings/pyroot/cppyy/CPyCppyy/src/TemplateProxy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions bindings/pyroot/cppyy/cppyy/test/test_templates.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pytest, os

Check failure on line 1 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F401)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:1:16: F401 `os` imported but unused help: Remove unused import: `os`

Check failure on line 1 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E401)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:1:1: E401 Multiple imports on one line help: Split imports
from pytest import mark, raises
from support import setup_make, pylong, IS_WINDOWS

Check failure on line 3 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F401)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:3:41: F401 `support.IS_WINDOWS` imported but unused help: Remove unused import

Check failure on line 3 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F401)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:3:21: F401 `support.setup_make` imported but unused help: Remove unused import

Check failure on line 3 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (I001)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:1:1: I001 Import block is un-sorted or un-formatted help: Organize imports

Expand All @@ -23,8 +23,8 @@
def test01_template_member_functions(self):
"""Template member functions lookup and calls"""

import cppyy
import sys

Check failure on line 27 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (I001)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:26:9: I001 Import block is un-sorted or un-formatted help: Organize imports

m = cppyy.gbl.MyTemplatedMethodClass()

Expand All @@ -40,7 +40,7 @@
if sys.hexversion >= 0x3000000:
targ = 'long'
else:
targ = long

Check failure on line 43 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F821)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:43:20: F821 Undefined name `long`
assert m.get_size[targ]() == m.get_long_size()

import ctypes
Expand Down Expand Up @@ -104,15 +104,15 @@
from cppyy.gbl.std import vector
# float in, float out
ggsr = cppyy.gbl.global_get_some_result['std::vector<float>']
assert type(ggsr(vector['float']([0.5])).m_retval) == float

Check failure on line 107 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E721)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:107:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
assert ggsr(vector['float']([0.5])).m_retval == 0.5
# int in, float out
ggsr = cppyy.gbl.global_get_some_result['std::vector<int>']
assert type(ggsr(vector['int']([5])).m_retval) == float

Check failure on line 111 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E721)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:111:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
assert ggsr(vector['int']([5])).m_retval == 5.
# float in, int out
ggsr = cppyy.gbl.global_get_some_result['std::vector<float>, int']
assert type(ggsr(vector['float']([0.3])).m_retval) == int

Check failure on line 115 in bindings/pyroot/cppyy/cppyy/test/test_templates.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E721)

bindings/pyroot/cppyy/cppyy/test/test_templates.py:115:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
assert ggsr(vector['float']([0.3])).m_retval == 0
# int in, int out
ggsr = cppyy.gbl.global_get_some_result['std::vector<int>, int']
Expand Down Expand Up @@ -1206,6 +1206,27 @@

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 <typename T>
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:
Expand Down
Loading