Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0f0de02

Browse files
committed
Implement __sub__/__rsub__.
1 parent0199137 commit0f0de02

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

‎vm/src/vm.rs‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,22 @@ impl VirtualMachine {
438438

439439
pubfn_sub(&mutself,a:PyObjectRef,b:PyObjectRef) ->PyResult{
440440
// Try __sub__, next __rsub__, next, give up
441-
self.call_method(&a,"__sub__",vec![b])
442-
/*
443-
if a.has_attr("__sub__") {
444-
self.call_method(&a, "__sub__", vec![b])
445-
} else if b.has_attr("__rsub__") {
446-
self.call_method(&b, "__rsub__", vec![a])
441+
ifletOk(method) =self.get_method(a.clone(),"__sub__"){
442+
self.invoke(
443+
method,
444+
PyFuncArgs{
445+
args:vec![b],
446+
kwargs:vec![],
447+
},
448+
)
449+
}elseifletOk(method) =self.get_method(b.clone(),"__rsub__"){
450+
self.invoke(
451+
method,
452+
PyFuncArgs{
453+
args:vec![a],
454+
kwargs:vec![],
455+
},
456+
)
447457
}else{
448458
// Cannot sub a and b
449459
let a_type_name = objtype::get_type_name(&a.typ());
@@ -453,7 +463,6 @@ impl VirtualMachine {
453463
a_type_name, b_type_name
454464
)))
455465
}
456-
*/
457466
}
458467

459468
pubfn_add(&mutself,a:PyObjectRef,b:PyObjectRef) ->PyResult{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp