-
Notifications
You must be signed in to change notification settings - Fork 265
Throw TypeError when subclasses forget to call __init__ #1224
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
base: master
Are you sure you want to change the base?
Conversation
virtuald
commented
Nov 24, 2025
- Based on Throw TypeError when subclasses forget to call __init__ pybind/pybind11#2152
- Fixes [BUG]: nanobind fails with unhelpful error message when super.__init__ isn't called by overridden constructor #1210
|
|
||
| with pytest.warns( | ||
| RuntimeWarning, | ||
| match="nanobind: attempted to access an uninitialized instance of type", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any other test that checks for this string, but the place where the documentation discusses it is talking about a unique_ptr ownership transfer, which isn't this?
| { Py_tp_dealloc, (void *) nb_type_dealloc }, | ||
| { Py_tp_setattro, (void *) nb_type_setattro }, | ||
| { Py_tp_init, (void *) nb_type_init }, | ||
| { Py_tp_call, (void *) nb_type_call }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a vectorcall instead?
|
I am not opposed to improving the error message, but this seems to complex of a change to achieve that goal. It also has a performance cost even in the non-erroneous case. |
831784f to
04a20d3
Compare
|
You're right, I was overthinking it. Now the extra overhead is just an single comparison. |
|
Never mind, my local test environment was stale when I tested it. I'll take a closer look tonight. |
04a20d3 to
dbdb24a
Compare
|
Well, I got rid of the MRO stuff so it's a lot simpler now. I feel like the other performance improvement would be to convert this tp_call to vectorcall, but I haven't been successful at that yet. Edit: Ok, I got it using vectorcall when not using the limited API in Python 3.13.. and it looks like |
|
Instead of the current approach, how about a warning ( |