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

Commita2ce4c8

Browse files
committed
Add special case handling for __get__(None, NoneType)
1 parent7bf8378 commita2ce4c8

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

‎vm/src/obj/objfunction.rs‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
usesuper::super::pyobject::{
2-
AttributeProtocol,PyContext,PyFuncArgs,PyObject,PyObjectKind,PyObjectRef,PyResult,
3-
TypeProtocol,
2+
AttributeProtocol,IdProtocol,PyContext,PyFuncArgs,PyObject,PyObjectKind,PyObjectRef,
3+
PyResult,TypeProtocol,
44
};
55
usesuper::super::vm::VirtualMachine;
66
usesuper::objtype;
@@ -22,7 +22,17 @@ pub fn init(context: &PyContext) {
2222
}
2323

2424
fnbind_method(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
25-
Ok(vm.new_bound_method(args.args[0].clone(), args.args[1].clone()))
25+
arg_check!(
26+
vm,
27+
args,
28+
required =[(function,None),(obj,None),(cls,None)]
29+
);
30+
31+
if obj.is(&vm.get_none()) && !cls.is(&obj.typ()){
32+
Ok(function.clone())
33+
}else{
34+
Ok(vm.ctx.new_bound_method(function.clone(), obj.clone()))
35+
}
2636
}
2737

2838
fnmember_get(vm:&mutVirtualMachine,mutargs:PyFuncArgs) ->PyResult{
@@ -50,7 +60,7 @@ fn classmethod_get(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
5060
match cls.get_attr("function"){
5161
Some(function) =>{
5262
let py_obj = owner.clone();
53-
let py_method = vm.new_bound_method(function, py_obj);
63+
let py_method = vm.ctx.new_bound_method(function, py_obj);
5464
Ok(py_method)
5565
}
5666
None =>{

‎vm/src/obj/objproperty.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn property_get(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
3131

3232
match cls.get_attr("fget"){
3333
Some(getter) =>{
34-
let py_method = vm.new_bound_method(getter, inst.clone());
34+
let py_method = vm.ctx.new_bound_method(getter, inst.clone());
3535
vm.invoke(py_method,PyFuncArgs::default())
3636
}
3737
None =>{

‎vm/src/vm.rs‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use super::obj::objsequence;
1717
usesuper::obj::objstr;
1818
usesuper::obj::objtype;
1919
usesuper::pyobject::{
20-
AttributeProtocol,DictProtocol,IdProtocol,PyContext,PyFuncArgs,PyObjectKind,PyObjectRef,
21-
PyResult,TypeProtocol,
20+
AttributeProtocol,DictProtocol,PyContext,PyFuncArgs,PyObjectKind,PyObjectRef,PyResult,
21+
TypeProtocol,
2222
};
2323
usesuper::stdlib;
2424
usesuper::sysmodule;
@@ -92,14 +92,6 @@ impl VirtualMachine {
9292
self.ctx.none()
9393
}
9494

95-
pubfnnew_bound_method(&self,function:PyObjectRef,object:PyObjectRef) ->PyObjectRef{
96-
if object.is(&self.get_none()){
97-
function
98-
}else{
99-
self.ctx.new_bound_method(function, object)
100-
}
101-
}
102-
10395
pubfnget_type(&self) ->PyObjectRef{
10496
self.ctx.type_type()
10597
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp