New submission from Ronald Oussoren:
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.
----------
components: Interpreter Core
messages: 182959
nosy: ronaldoussoren
priority: low
severity: normal
stage: needs patch
status: open
title: __slots__ on PyVarObject subclass
versions: Python 3.4
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue17295>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com