tp_base, tp_basesize, and __slots__ instance __class__ reassignment

"Martin v. Löwis" martin at v.loewis.de
Sun Jul 6 03:17:11 EDT 2003


Jp Calderone wrote:

>   Can anyone enlighten me?

The test doesn't recognize the addition of arbitrary same slots.
Instead, it only looks for the __dict__ slot and the weakrefs slot.
If any additional slots have been added to either subclass, the
classes are considered different.

To test whether just these two slots have been added in lock-step,
you check
1. the dictoffset is the same for both classes, and it follows
    immediately the base slots, or neither class has a dictoffset.
2. the weakrefs offset is the same for both classes, and it follows
    immediately the dictoffset (or the base slots if there was no
    dictoffset).
3. there are no additional slots

Now, this *could* be generalized to treating to classes the same if
they have the same user-defined slots. If you want to do that, looking
at the size is not sufficient - you also have to verify that the slot
names and offsets are the same, lock-step-wise.

HTH,
Martin





More information about the Python-list mailing list