Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: move __class__ layout check to builtin_type snippet
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
  • Loading branch information
Copilot and youknowone committed Dec 26, 2025
commit 71e9eb7431741c9862ad16b302e4a1e84d5ea0bb
27 changes: 0 additions & 27 deletions crates/vm/src/vm/interpreter.rs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding test in rust code, add test test in builtin_type.py

Original file line number Diff line number Diff line change
Expand Up @@ -169,31 +169,4 @@ mod tests {
assert_eq!(value.as_str(), "Hello Hello Hello Hello ")
})
}

#[test]
fn class_assignment_layout_mismatch_error() {
Interpreter::without_stdlib(Default::default()).enter(|vm| {
let scope = vm.new_scope_with_builtins();
let source = r#"
class TypeA:
def __init__(self):
self.a = 1

class TypeB:
__slots__ = "b"
def __init__(self):
self.b = 2

obj = TypeA()
try:
obj.__class__ = TypeB
except TypeError as e:
assert str(e) == "__class__ assignment: 'TypeB' object layout differs from 'TypeA'"
else:
raise AssertionError("TypeError not raised")
"#;
vm.run_code_string(scope, source, "<test>".to_owned())
.expect("script should complete without uncaught exceptions");
})
}
}
20 changes: 20 additions & 0 deletions extra_tests/snippets/builtin_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,26 @@ class C(B, BB):
assert C.mro() == [C, B, A, BB, AA, object]


class TypeA:
def __init__(self):
self.a = 1


class TypeB:
__slots__ = "b"

def __init__(self):
self.b = 2


obj = TypeA()
with assert_raises(TypeError) as cm:
obj.__class__ = TypeB
assert "__class__ assignment: 'TypeB' object layout differs from 'TypeA'" in str(
cm.exception
)


assert type(Exception.args).__name__ == "getset_descriptor"
assert type(None).__bool__(None) is False

Expand Down