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
8 changes: 7 additions & 1 deletion src/cpyrt/Utility.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ std::string cpyrt::Utility::ConstructTemplateArgs(PyObject* pyname,
(args ? PyTuple_GET_ITEM(args, i) : nullptr), pref,
pcnt)) {
PyErr_SetString(
PyExc_SyntaxError,
PyExc_TypeError,
"could not construct C++ name from provided template argument.");
return "";
}
Expand Down Expand Up @@ -827,6 +827,12 @@ static bool AddTypeName(std::vector<Cpp::TemplateArgInfo>& types, PyObject* tn,
if (tpName) {
interop::TCppType_t type = interop::GetType(
cpyrt_PyText_AsString(tpName), /* enable_slow_lookup */ true);
if (!type) {
// any Python object has a __name__; one that does not name a C++
// type contributes no argument
Py_DECREF(tpName);
continue;
}
if (interop::IsEnumType(type)) {
PyObject* value_int = PyNumber_Index(tn);
if (!value_int) {
Expand Down
12 changes: 12 additions & 0 deletions test/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1631,3 +1631,15 @@ def test51_nontype_enum_template_arg(self):

# ...nor leave the interpreter unable to compile a later call wrapper
assert ns.probe(41) == 42

def test52_no_cpp_name_for_template_arg(self):
"""Template arguments with no C++ equivalent raise TypeError"""

import cppjit

# a lambda has a __name__ ("<lambda>") that resolves to no C++ type
with raises(TypeError):
cppjit.gbl.std.vector[lambda: None]

with raises(TypeError):
cppjit.gbl.std.vector[object()]
Loading