1
1
use super :: super :: pyobject:: {
2
- AttributeProtocol , PyContext , PyFuncArgs , PyObject , PyObjectKind , PyObjectRef , PyResult ,
3
- TypeProtocol ,
2
+ AttributeProtocol , IdProtocol , PyContext , PyFuncArgs , PyObject , PyObjectKind , PyObjectRef ,
3
+ PyResult , TypeProtocol ,
4
4
} ;
5
5
use super :: super :: vm:: VirtualMachine ;
6
6
use super :: objtype;
@@ -22,7 +22,17 @@ pub fn init(context: &PyContext) {
22
22
}
23
23
24
24
fn bind_method ( vm : & mut VirtualMachine , 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
+ }
26
36
}
27
37
28
38
fn member_get ( vm : & mut VirtualMachine , mut args : PyFuncArgs ) -> PyResult {
@@ -50,7 +60,7 @@ fn classmethod_get(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
50
60
match cls. get_attr ( "function" ) {
51
61
Some ( function) => {
52
62
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) ;
54
64
Ok ( py_method)
55
65
}
56
66
None => {
0 commit comments