@@ -40,22 +40,6 @@ pub struct PyFunction {
4040 kw_only_defaults : Option < PyDictRef > ,
4141}
4242
43- impl SlotDescriptor for PyFunction {
44- fn descr_get (
45- vm : & VirtualMachine ,
46- zelf : PyObjectRef ,
47- obj : Option < PyObjectRef > ,
48- cls : OptionalArg < PyObjectRef > ,
49- ) -> PyResult {
50- let ( zelf, obj) = Self :: _unwrap ( zelf, obj, vm) ?;
51- if vm. is_none ( & obj) && !Self :: _cls_is ( & cls, & obj. class ( ) ) {
52- Ok ( zelf. into_object ( ) )
53- } else {
54- Ok ( vm. ctx . new_bound_method ( zelf. into_object ( ) , obj) )
55- }
56- }
57- }
58-
5943impl PyFunction {
6044 pub fn new (
6145 code : PyCodeRef ,
@@ -285,14 +269,8 @@ impl PyValue for PyFunction {
285269 }
286270}
287271
288- #[ pyimpl( with( SlotDescriptor ) , flags( HAS_DICT ) ) ]
272+ #[ pyimpl( with( SlotDescriptor , SlotCall ) , flags( HAS_DICT ) ) ]
289273impl PyFunction {
290- #[ pyslot]
291- #[ pymethod( magic) ]
292- fn call ( & self , args : PyFuncArgs , vm : & VirtualMachine ) -> PyResult {
293- self . invoke ( args, vm)
294- }
295-
296274 #[ pyproperty( magic) ]
297275 fn code ( & self ) -> PyCodeRef {
298276 self . code . clone ( )
@@ -326,6 +304,28 @@ impl PyFunction {
326304 }
327305}
328306
307+ impl SlotDescriptor for PyFunction {
308+ fn descr_get (
309+ vm : & VirtualMachine ,
310+ zelf : PyObjectRef ,
311+ obj : Option < PyObjectRef > ,
312+ cls : OptionalArg < PyObjectRef > ,
313+ ) -> PyResult {
314+ let ( zelf, obj) = Self :: _unwrap ( zelf, obj, vm) ?;
315+ if vm. is_none ( & obj) && !Self :: _cls_is ( & cls, & obj. class ( ) ) {
316+ Ok ( zelf. into_object ( ) )
317+ } else {
318+ Ok ( vm. ctx . new_bound_method ( zelf. into_object ( ) , obj) )
319+ }
320+ }
321+ }
322+
323+ impl SlotCall for PyFunction {
324+ fn call ( zelf : PyRef < Self > , args : PyFuncArgs , vm : & VirtualMachine ) -> PyResult {
325+ zelf. invoke ( args, vm)
326+ }
327+ }
328+
329329#[ pyclass( module = false , name = "method" ) ]
330330#[ derive( Debug ) ]
331331pub struct PyBoundMethod {
@@ -335,9 +335,9 @@ pub struct PyBoundMethod {
335335}
336336
337337impl SlotCall for PyBoundMethod {
338- fn call ( & self , args : PyFuncArgs , vm : & VirtualMachine ) -> PyResult {
339- let args = args. insert ( self . object . clone ( ) ) ;
340- vm. invoke ( & self . function , args)
338+ fn call ( zelf : PyRef < Self > , args : PyFuncArgs , vm : & VirtualMachine ) -> PyResult {
339+ let args = args. insert ( zelf . object . clone ( ) ) ;
340+ vm. invoke ( & zelf . function , args)
341341 }
342342}
343343
0 commit comments