Skip to content
Merged
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: 2 additions & 2 deletions bindings/pyroot/cppyy/CPyCppyy/src/TemplateProxy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,8 @@ static PyObject* tpp_call(TemplateProxy* pytmpl, PyObject* args, PyObject* kwds)
int pcnt = 0;
pymeth = pytmpl->Instantiate(pytmpl->fTI->fCppName, args, nargsf, pref, &pcnt);
if (pymeth) {
// attempt actual call; argument based, so do not allow implicit conversions
result = CallMethodImp(pytmpl, pymeth, args, nargsf, kwds, false, sighash);
// attempt actual call; even if argument based, allow implicit conversions, for example for non-template arguments
result = CallMethodImp(pytmpl, pymeth, args, nargsf, kwds, true, sighash);
if (result) TPPCALL_RETURN;
}
Utility::FetchError(errors);
Expand Down
23 changes: 23 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

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
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

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

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

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

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 @@ -1184,6 +1184,29 @@
with pytest.raises(TypeError, match=r"could not construct C\+\+ name"):
cppyy.gbl.test35_func[set(), list()]()

def test36_constructor_implicit_conversion(self):
"""Implicit conversion to call a templated constructor"""

import cppyy

cppyy.cppdef("""\
namespace ConstructorImplicitConversion {
struct IntWrapper {
IntWrapper(int i) : m_i(i) {}
int m_i;
};
struct S {
template <typename T>
S(IntWrapper a, T b) : m_a(a.m_i) {}

int m_a = 0;
}; }""")

ns = cppyy.gbl.ConstructorImplicitConversion

a = ns.S(1, 2)
assert a.m_a == 1


class TestTEMPLATED_TYPEDEFS:
def setup_class(cls):
Expand Down
Loading