From 8864627502280e3d19c874eed25b42ead1ccf5cc Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Tue, 29 Oct 2024 06:31:53 +0000 Subject: [PATCH] changes to make sure `dm_set` is called when assigning a value to an enum resulting in raising TypeError --- src/CPPScope.cxx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/CPPScope.cxx b/src/CPPScope.cxx index b72b3f6..0058f12 100644 --- a/src/CPPScope.cxx +++ b/src/CPPScope.cxx @@ -431,10 +431,7 @@ static PyObject* meta_getattro(PyObject* pyclass, PyObject* pyname) if (attr) { // cache the result if (CPPDataMember_Check(attr)) { - if (Cppyy::IsClass(scope)) - PyType_Type.tp_setattro(pyclass, pyname, attr); - else - PyType_Type.tp_setattro((PyObject*)Py_TYPE(pyclass), pyname, attr); + PyType_Type.tp_setattro((PyObject*)Py_TYPE(pyclass), pyname, attr); Py_DECREF(attr); // The call below goes through "dm_get" @@ -531,13 +528,11 @@ static int meta_setattro(PyObject* pyclass, PyObject* pyname, PyObject* pyval) // the C++ side, b/c there is no descriptor yet. This triggers the creation for // for such data as necessary. The many checks to narrow down the specific case // are needed to prevent unnecessary lookups and recursion. - if (((CPPScope*)pyclass)->fFlags & CPPScope::kIsNamespace) { // skip if the given pyval is a descriptor already, or an unassignable class - if (!CPyCppyy::CPPDataMember_Check(pyval) && !CPyCppyy::CPPScope_Check(pyval)) { - std::string name = CPyCppyy_PyText_AsString(pyname); - if (Cppyy::GetNamed(name, ((CPPScope*)pyclass)->fCppType)) - meta_getattro(pyclass, pyname); // triggers creation - } + if (!CPyCppyy::CPPDataMember_Check(pyval) && !CPyCppyy::CPPScope_Check(pyval)) { + std::string name = CPyCppyy_PyText_AsString(pyname); + if (Cppyy::GetNamed(name, ((CPPScope*)pyclass)->fCppType)) + meta_getattro(pyclass, pyname); // triggers creation } return PyType_Type.tp_setattro(pyclass, pyname, pyval);