Skip to content

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

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?

Activity

  1. added 4 commits that reference this issue on Apr 5, 2020
    5c6a04c
    0146834
    4fa23a4
    5e5d3cf
  2. added a commit that references this issue on May 2, 2020
    8383222
  3. added 2 commits that reference this issue on Jun 16, 2020
    548e920
    674a400
  4. added a commit that references this issue on Jul 7, 2020
    1b0bf35
  5. added a commit that references this issue on Aug 3, 2020
    0bf6fbf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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