Open
Description
Currently you are allowed to have the following:
class Weird(str, int):
pass
But this causes issues using using instances of this class as both str
and int
expect the payload to be PyString
and PyInt
respectively, but the object can only have a single payload.
>>>>> 2 + Weird()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: Unexpected payload for type "Weird"
CPython deals with this by raising an error during class construction time:
>>> class Weird(str, int):
... pass
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: multiple bases have instance lay-out conflict
I feel we should do a similar thing by detecting when bases have different payloads.
This also comes up in __class__
assignment, the following is CPython behavior:
>>> class A(str): pass
...
>>> class B(int): pass
...
>>> A().__class__ = B
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __class__ assignment: 'B' object layout differs from 'A'