Skip to content

Commit 8c420bb

Browse files
committed
Match _testinternalcapi hamt and InstructionSequence constructor arguments
hamt() ignores its arguments and returns an empty hamt. On the exact InstructionSequence type, positional arguments raise "InstructionSequenceType() takes no positional arguments" and keyword arguments raise "InstructionSequenceType() takes no keyword arguments". Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7
1 parent bea6ceb commit 8c420bb

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎crates/vm/src/stdlib/_testinternalcapi.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,10 @@ mod _testinternalcapi {
843843
impl Constructor for Hamt {
844844
type Args = ();
845845

846+
fn slot_new(cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {
847+
Self::default().into_ref_with_type(vm, cls).map(Into::into)
848+
}
849+
846850
fn py_new(_cls: &Py<PyType>, _args: Self::Args, _vm: &VirtualMachine) -> PyResult<Self> {
847851
Ok(Self::default())
848852
}
@@ -1197,6 +1201,22 @@ mod _testinternalcapi {
11971201
impl Constructor for PyInstructionSequence {
11981202
type Args = ();
11991203

1204+
fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
1205+
if cls.is(Self::class(&vm.ctx)) {
1206+
if !args.args.is_empty() {
1207+
return Err(vm.new_type_error(
1208+
"InstructionSequenceType() takes no positional arguments",
1209+
));
1210+
}
1211+
if !args.kwargs.is_empty() {
1212+
return Err(
1213+
vm.new_type_error("InstructionSequenceType() takes no keyword arguments")
1214+
);
1215+
}
1216+
}
1217+
Self::empty().into_ref_with_type(vm, cls).map(Into::into)
1218+
}
1219+
12001220
fn py_new(_cls: &Py<PyType>, _args: Self::Args, _vm: &VirtualMachine) -> PyResult<Self> {
12011221
Ok(Self::empty())
12021222
}

0 commit comments

Comments
 (0)