Summary
Setting object's class attribute to a type with different layout cause panic
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', vm/src/object/core.rs:813:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
which is an error in cpython
TypeError: __class__ assignment: 'TypeB' object layout differs from 'TypeA'
Detailed Explanation
class TypeA:
def __init__(self) -> None:
self.a = 1
class TypeB:
__slots__ = "b"
def __init__(self) -> None:
self.b = 2
obj = TypeA()
assert obj.a == 1
obj.__class__ = TypeB
print(obj.b)
Reactions are currently unavailable
Summary
Setting object's class attribute to a type with different layout cause panic
which is an error in cpython
Detailed Explanation
class TypeA: def __init__(self) -> None: self.a = 1 class TypeB: __slots__ = "b" def __init__(self) -> None: self.b = 2 obj = TypeA() assert obj.a == 1 obj.__class__ = TypeB print(obj.b)