Skip to content

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

Closed
@virtuald

Description

@virtuald

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions