Visitar URL original
Panic when setting __class__ with different layout · Issue #4634 · RustPython/RustPython · GitHub
Skip to content

Panic when setting __class__ with different layout #4634

Description

@qingshi163

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)

Activity

  1. youknowone commented on Mar 5, 2023

    @youknowone
    Member

    maybe similar thing cause both this one and #1979

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

RFCRequest for comments

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions