New submission from Dan Snider <mr.assume.a...@gmail.com>:

>>> class a(dict): __slots__ = '__dict__', 'x'

>>> class b(dict): __slots__ = '__dict__', 'x'

>>> self = a(); self.__class__ = b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    self=a(); self.__class__ = b
TypeError: __class__ assignment: 'b' object layout differs from 'a'

This always occurs when __dict__ and/or __weakref__ are defined as slots, even 
when both classes have otherwise identical slots. This behavior appears to 
contradict what the docs say wrt to __class__ assignment, which is (in its 
entirety):

"__class__ assignment works only if both classes have the same __slots__. "

Not sure if this is just a case of ambiguous documentation and intentional 
behavior or not. Since two classes with identical slots will always have 
identical internal struct layouts, I can't see a reason for this error.

----------
messages: 328296
nosy: bup
priority: normal
severity: normal
status: open
title: Can't reassign __class__ despite the assigned class having identical 
slots
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35048>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

  • ... Dan Snider
    • ... శ్రీనివాస్ రెడ్డి తాటిపర్తి
    • ... Karthikeyan Singaravelan

Reply via email to