-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
__slots__ on PyVarObject subclass #61497
Comments
Currently a subclass of a PyVarObject (such as 'int') cannot use a non-empty slots, for example: >>> class L (int):
... __slots__ = ('a', 'b')
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: nonempty __slots__ not supported for subtype of 'int'
>>> However, subclasses that don't use __slots__ do have an implicit slot: the __dict__ value. Wouldn't it be possible to use the trick used for tp_dictoffset for slots as well, that is use negative values for the slot offsets and access them from the end of the object? The major problem with an implementation is that PyMember_GetOne has a 'char*' argument instead of a 'PyObject*' one, but that's easily changed (PyMember_GetOne is currently only called in Object/descrobject.c and that call casts PyObject* to char*. This would be an API change, but AFAIK PyMember_GetOne is not documented at the moment (and changing the argument type would be binary compatible). I hope to work on a patch in the near future. |
Probably a duplicate of bpo-1173475. Do you want to work on the patch there? |
You're right, this is a duplicate. |
I closed the issue, but I didn't see that bpo-1173475 was closed. Sorry, I reopened this issue again. |
Encountered this when trying to add some fields to urllib.parse.SplitResult for bpo-22852. bpo-1173475 has a patch; I haven’t tried using it though. |
For this to work, the interpreter must know the type's memory layout. Let's use gh-103740 for enabling this with |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: