@@ -3,8 +3,9 @@ use crate::{
3
3
builtins:: builtinfunc:: PyBuiltinMethod ,
4
4
class:: PyClassImpl ,
5
5
function:: { FuncArgs , IntoPyNativeFunc } ,
6
- types:: { Callable , Constructor , GetDescriptor } ,
6
+ types:: { Callable , Constructor , GetDescriptor , Initializer } ,
7
7
Context , PyObjectRef , PyPayload , PyRef , PyResult , VirtualMachine ,
8
+ AsObject
8
9
} ;
9
10
10
11
#[ pyclass( module = false , name = "staticmethod" ) ]
@@ -62,7 +63,17 @@ impl PyStaticMethod {
62
63
}
63
64
}
64
65
65
- #[ pyimpl( with( Callable , GetDescriptor , Constructor ) , flags( BASETYPE , HAS_DICT ) ) ]
66
+ impl Initializer for PyStaticMethod {
67
+ type Args = PyObjectRef ;
68
+
69
+ fn init ( zelf : PyRef < Self > , args : Self :: Args , vm : & VirtualMachine ) -> PyResult < ( ) > {
70
+ zelf. as_object ( ) . set_attr ( "__doc__" , args. get_attr ( "__doc__" , vm) ?, vm) ?;
71
+ // zelf.as_object().set_attr("__format__", args.get_attr("__format__", vm)?, vm);
72
+ Ok ( ( ) )
73
+ }
74
+ }
75
+
76
+ #[ pyimpl( with( Callable , GetDescriptor , Constructor , Initializer ) , flags( BASETYPE , HAS_DICT ) ) ]
66
77
impl PyStaticMethod {
67
78
#[ pyproperty( magic) ]
68
79
fn isabstractmethod ( & self , vm : & VirtualMachine ) -> PyObjectRef {
@@ -72,11 +83,46 @@ impl PyStaticMethod {
72
83
}
73
84
}
74
85
86
+ #[ pyproperty( magic) ]
87
+ fn func ( & self , vm : & VirtualMachine ) -> PyObjectRef {
88
+ self . callable . clone ( )
89
+ }
90
+
91
+ #[ pyproperty( magic) ]
92
+ fn wrapped ( & self , vm : & VirtualMachine ) -> PyObjectRef {
93
+ self . callable . clone ( )
94
+ }
95
+
75
96
#[ pyproperty( magic, setter) ]
76
97
fn set_isabstractmethod ( & self , value : PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
77
98
self . callable . set_attr ( "__isabstractmethod__" , value, vm) ?;
78
99
Ok ( ( ) )
79
100
}
101
+
102
+ #[ pymethod( magic) ]
103
+ fn repr ( & self , vm : & VirtualMachine ) -> PyResult < String > {
104
+ Ok ( format ! ( "<staticmethod({})>" , self . callable. repr( vm) ?) )
105
+ }
106
+
107
+ #[ pyproperty( magic) ]
108
+ fn module ( & self , vm : & VirtualMachine ) -> PyResult {
109
+ self . callable . get_attr ( "__module__" , vm)
110
+ }
111
+
112
+ #[ pyproperty( magic) ]
113
+ fn name ( & self , vm : & VirtualMachine ) -> PyResult {
114
+ self . callable . get_attr ( "__name__" , vm)
115
+ }
116
+
117
+ #[ pyproperty( magic) ]
118
+ fn qualname ( & self , vm : & VirtualMachine ) -> PyResult {
119
+ self . callable . get_attr ( "__qualname__" , vm)
120
+ }
121
+
122
+ #[ pyproperty( magic) ]
123
+ fn annotations ( & self , vm : & VirtualMachine ) -> PyResult {
124
+ self . callable . get_attr ( "__annotations__" , vm)
125
+ }
80
126
}
81
127
82
128
impl Callable for PyStaticMethod {
0 commit comments