Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in deriving from C++ classes with protected data members with Python 3.13 #273

Open
guitargeek opened this issue Nov 7, 2024 · 2 comments

Comments

@guitargeek
Copy link
Contributor

Reproducer:

import cppyy

cppyy.cppdef("""

class MyBaseClass{
public:
   virtual ~MyBaseClass() = default;
protected:
   int _data = 0;
};

""")

class MyDerivedClass(cppyy.gbl.MyBaseClass):
    pass

The error:

Traceback (most recent call last):
  File "reproducer.py", line 14, in <module>
    class MyDerivedClass(cppyy.gbl.MyBaseClass):
        pass
KeyError: '_data'
@guitargeek
Copy link
Contributor Author

guitargeek commented Nov 7, 2024

Can be fixed like this: root-project/root#16851

@wlav
Copy link
Owner

wlav commented Nov 7, 2024

The example above doesn't fail for me.

It's also not clear to which part you are referring in the above, but if this:

#if PY_VERSION_HEX < 0x30d00f0
         PyObject* pyf = PyMapping_GetItemString(disp_dct, (char*)name.c_str());
#else
         PyObject* pyf = nullptr;
         PyMapping_GetOptionalItemString(disp_dct, (char*)name.c_str(), &pyf);
#endif

then all that does is suppress the exception, not solve the issue. It's also not Py3.13 specific.

That is, in your case, does this work (it does for me):

class MyDerivedClass(cppyy.gbl.MyBaseClass):
    def gime(self):
        return self._data

m = MyDerivedClass()
print(m.gime())

B/c if only the error is suppressed with the "fix", then the above will still fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants