homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: __slots__ on PyVarObject subclass
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.4
process
Status: open Resolution: duplicate
Dependencies: Superseder: __slots__ for subclasses of variable length types
View: 1173475
Assigned To: Nosy List: amaury.forgeotdarc, martin.panter, ronaldoussoren, vstinner
Priority: low Keywords:

Created on 2013年02月25日 16:24 by ronaldoussoren, last changed 2022年04月11日 14:57 by admin.

Messages (5)
msg182959 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013年02月25日 16:24
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.
msg184637 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2013年03月19日 15:10
Probably a duplicate of issue1173475. Do you want to work on the patch there?
msg184640 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013年03月19日 15:31
You're right, this is a duplicate.
msg185397 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013年03月28日 01:21
I closed the issue, but I didn't see that #1173475 was closed. Sorry, I reopened this issue again.
msg237914 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015年03月12日 05:27
Encountered this when trying to add some fields to urllib.parse.SplitResult for Issue 22852. Issue 1173475 has a patch; I haven’t tried using it though.
History
Date User Action Args
2022年04月11日 14:57:42adminsetgithub: 61497
2015年03月12日 05:27:03martin.pantersetnosy: + martin.panter
messages: + msg237914
2013年03月28日 01:21:29vstinnersetstatus: closed -> open
nosy: + vstinner
messages: + msg185397

2013年03月28日 01:20:40vstinnersetstatus: open -> closed
2013年03月19日 15:31:32ronaldoussorensetresolution: duplicate
messages: + msg184640

type: behavior
superseder: __slots__ for subclasses of variable length types
stage: needs patch -> resolved
2013年03月19日 15:10:31amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg184637
2013年02月25日 16:24:22ronaldoussorencreate

AltStyle によって変換されたページ (->オリジナル) /