Skip to content

Commit 529f920

Browse files
Vipul-Cariappaaaronj0
authored andcommitted
fix type converters function resolution
changes to make sure `dm_set` is called when assigning a value to an enum resulting in raising TypeError
1 parent c4367c6 commit 529f920

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/CPPScope.cxx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,7 @@ static PyObject* meta_getattro(PyObject* pyclass, PyObject* pyname)
431431
if (attr) {
432432
// cache the result
433433
if (CPPDataMember_Check(attr)) {
434-
if (Cppyy::IsClass(scope))
435-
PyType_Type.tp_setattro(pyclass, pyname, attr);
436-
else
437-
PyType_Type.tp_setattro((PyObject*)Py_TYPE(pyclass), pyname, attr);
434+
PyType_Type.tp_setattro((PyObject*)Py_TYPE(pyclass), pyname, attr);
438435

439436
Py_DECREF(attr);
440437
// The call below goes through "dm_get"
@@ -531,13 +528,11 @@ static int meta_setattro(PyObject* pyclass, PyObject* pyname, PyObject* pyval)
531528
// the C++ side, b/c there is no descriptor yet. This triggers the creation for
532529
// for such data as necessary. The many checks to narrow down the specific case
533530
// are needed to prevent unnecessary lookups and recursion.
534-
if (((CPPScope*)pyclass)->fFlags & CPPScope::kIsNamespace) {
535531
// skip if the given pyval is a descriptor already, or an unassignable class
536-
if (!CPyCppyy::CPPDataMember_Check(pyval) && !CPyCppyy::CPPScope_Check(pyval)) {
537-
std::string name = CPyCppyy_PyText_AsString(pyname);
538-
if (Cppyy::GetNamed(name, ((CPPScope*)pyclass)->fCppType))
539-
meta_getattro(pyclass, pyname); // triggers creation
540-
}
532+
if (!CPyCppyy::CPPDataMember_Check(pyval) && !CPyCppyy::CPPScope_Check(pyval)) {
533+
std::string name = CPyCppyy_PyText_AsString(pyname);
534+
if (Cppyy::GetNamed(name, ((CPPScope*)pyclass)->fCppType))
535+
meta_getattro(pyclass, pyname); // triggers creation
541536
}
542537

543538
return PyType_Type.tp_setattro(pyclass, pyname, pyval);

src/Converters.cxx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3447,11 +3447,10 @@ CPyCppyy::Converter* CPyCppyy::CreateConverter(Cppyy::TCppType_t type, cdims_t d
34473447

34483448
if (!result && cpd == "&&") {
34493449
// for builtin, can use const-ref for r-ref
3450-
h = gConvFactories.find("const " + realTypeStr + " &");
3450+
h = gConvFactories.find("const " + realTypeStr + "&");
34513451
if (h != gConvFactories.end())
34523452
return (h->second)(dims);
3453-
std::string temp ="const " + realUnresolvedTypeStr + " &";
3454-
h = gConvFactories.find("const " + realUnresolvedTypeStr + " &");
3453+
h = gConvFactories.find("const " + realUnresolvedTypeStr + "&");
34553454
if (h != gConvFactories.end())
34563455
return (h->second)(dims);
34573456
// else, unhandled moves

0 commit comments

Comments
 (0)