-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
C-bugSomething isn't workingSomething isn't working
Description
Currently you are allowed to have the following:
class Weird(str, int):
passBut 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 conflictI 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'coolreader18
Metadata
Metadata
Assignees
Labels
C-bugSomething isn't workingSomething isn't working