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

Use pybind11 metaclass to detect when __init__ has not been called from subclass #2103

Closed
virtuald opened this issue Jan 30, 2020 · 0 comments · Fixed by #2152
Closed

Use pybind11 metaclass to detect when __init__ has not been called from subclass #2103

virtuald opened this issue Jan 30, 2020 · 0 comments · Fixed by #2152

Comments

@virtuald
Copy link
Contributor

virtuald commented Jan 30, 2020

My users are high school robotics teams, and the RobotPy project is wrapping a C++ library that uses a lot of inheritance. They keep inheriting from C++ objects, add a constructor without calling the super constructor, it crashes, and they don't really know why at first. It would be great if pybind11 could catch this and throw a python exception instead with a useful error message.

As noted in this stack overflow answer (https://stackoverflow.com/a/46120342), from a metaclass it's possible to call a function after __init__ is called (at least from Python anyways). Has anyone tried customizing the pybind11 metaclass to do this sort of detection?

virtuald added a commit to robotpy/pybind11 that referenced this issue Apr 5, 2020
virtuald added a commit to robotpy/pybind11 that referenced this issue Apr 5, 2020
virtuald added a commit to robotpy/pybind11 that referenced this issue Apr 5, 2020
virtuald added a commit to robotpy/pybind11 that referenced this issue Apr 5, 2020
virtuald added a commit to robotpy/pybind11 that referenced this issue May 2, 2020
virtuald added a commit to robotpy/pybind11 that referenced this issue Jun 16, 2020
virtuald added a commit to robotpy/pybind11 that referenced this issue Jun 22, 2020
EricCousineau-TRI pushed a commit to EricCousineau-TRI/pybind11 that referenced this issue Aug 3, 2020
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.

1 participant