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

For Python subclass, forgetting to call C++ superclass __init__ constructor is painful #1577

Closed
EricCousineau-TRI opened this issue Oct 24, 2018 · 2 comments

Comments

@EricCousineau-TRI
Copy link
Collaborator

EricCousineau-TRI commented Oct 24, 2018

While it is noted here in the docs:
https://pybind11.readthedocs.io/en/stable/advanced/classes.html#overriding-virtual-functions-in-python
it is still sometimes easy to forget. If it were somehow possible, it'd be nice to robustly detect access to unconstructed base classes. (... though it may be a big performance penalty, so I'm fine with this being closed as "Not a Problem")

Example failure case from above:

class Dachschund(Dog):
    def __init__(self, name):
        # Oops!
        self.name = name

    def bark(self):
        return "yap!"

d = Dog("Sir Schnitzel")
d.go(10)  # Nuts!

Had run into it when writing this example, and then felt dumb once I realized what the problem was.

@bstaletic
Copy link
Collaborator

Considering that we've merged #2152, can we close this now?

@YannickJadoul
Copy link
Collaborator

I say we can.

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

3 participants