Skip to content

Broken mro when using multiple inheritance with py::metaclass #597

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

Closed
pschella opened this issue Jan 6, 2017 · 3 comments · Fixed by #679
Closed

Broken mro when using multiple inheritance with py::metaclass #597

pschella opened this issue Jan 6, 2017 · 3 comments · Fixed by #679

Comments

@pschella
Copy link
Contributor

pschella commented Jan 6, 2017

When a derived class MroDerived needs to expose a static attribute (which necessitates using py::metaclass), but also inherits from multiple bases Python raises the following error:

ImportError: MroDerived: PyType_Ready failed (TypeError: mro() returned base with unsuitable layout ('pybind11_tests.MroBaseB'))!

For a complete example see https://github.com/lsst-dm/pybind11/tree/broken_mro

@pschella
Copy link
Contributor Author

pschella commented Jan 9, 2017

This is on Python 3.5.2.

@r-owen
Copy link

r-owen commented Jan 9, 2017

I will also say that the need to add py::metaclass to all our code is a bit of a nuisance. It appears that once it has been specified for a given class it is needed for all subclasses of that class, as well, so it feels a bit fragile. What benefit does one derive by omitting it? If it's not a big drawback to use it then we'll probably just add it to all our code to avoid problems (and wish there was some way to make it the default).

@pschella
Copy link
Contributor Author

While I agree with it being a nuisance, this was already ruled upon by the lead developer.
However, adding py::metaclass to all classes does not resolve this problem.

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

Successfully merging a pull request may close this issue.

2 participants