@@ -14,7 +14,6 @@ use crate::{
1414pub type PyGetterFunc = Box < py_dyn_fn ! ( dyn Fn ( & VirtualMachine , PyObjectRef ) -> PyResult ) > ;
1515pub type PySetterFunc =
1616 Box < py_dyn_fn ! ( dyn Fn ( & VirtualMachine , PyObjectRef , PyObjectRef ) -> PyResult <( ) >) > ;
17- pub type PyDeleterFunc = Box < py_dyn_fn ! ( dyn Fn ( & VirtualMachine , PyObjectRef ) -> PyResult <( ) >) > ;
1817
1918pub trait IntoPyGetterFunc < T > : PyThreadingConstraint + Sized + ' static {
2019 fn get ( & self , obj : PyObjectRef , vm : & VirtualMachine ) -> PyResult ;
@@ -152,68 +151,12 @@ where
152151 }
153152}
154153
155- pub trait IntoPyDeleterFunc < T > : PyThreadingConstraint + Sized + ' static {
156- fn delete ( & self , obj : PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > ;
157- fn into_deleter ( self ) -> PyDeleterFunc {
158- Box :: new ( move |vm, obj| self . delete ( obj, vm) )
159- }
160- }
161-
162- impl < F , T , R > IntoPyDeleterFunc < ( OwnedParam < T > , R , VirtualMachine ) > for F
163- where
164- F : Fn ( T , & VirtualMachine ) -> R + ' static + Send + Sync ,
165- T : TryFromObject ,
166- R : IntoPyNoResult ,
167- {
168- fn delete ( & self , obj : PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
169- let obj = T :: try_from_object ( vm, obj) ?;
170- ( self ) ( obj, vm) . into_noresult ( )
171- }
172- }
173-
174- impl < F , S , R > IntoPyDeleterFunc < ( RefParam < S > , R , VirtualMachine ) > for F
175- where
176- F : Fn ( & S , & VirtualMachine ) -> R + ' static + Send + Sync ,
177- S : PyPayload ,
178- R : IntoPyNoResult ,
179- {
180- fn delete ( & self , obj : PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
181- let zelf = PyRef :: < S > :: try_from_object ( vm, obj) ?;
182- ( self ) ( & zelf, vm) . into_noresult ( )
183- }
184- }
185-
186- impl < F , T , R > IntoPyDeleterFunc < ( OwnedParam < T > , R ) > for F
187- where
188- F : Fn ( T ) -> R + ' static + Send + Sync ,
189- T : TryFromObject ,
190- R : IntoPyNoResult ,
191- {
192- fn delete ( & self , obj : PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
193- let obj = T :: try_from_object ( vm, obj) ?;
194- ( self ) ( obj) . into_noresult ( )
195- }
196- }
197-
198- impl < F , S , R > IntoPyDeleterFunc < ( RefParam < S > , R ) > for F
199- where
200- F : Fn ( & S ) -> R + ' static + Send + Sync ,
201- S : PyPayload ,
202- R : IntoPyNoResult ,
203- {
204- fn delete ( & self , obj : PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
205- let zelf = PyRef :: < S > :: try_from_object ( vm, obj) ?;
206- ( self ) ( & zelf) . into_noresult ( )
207- }
208- }
209-
210154#[ pyclass( module = false , name = "getset_descriptor" ) ]
211155pub struct PyGetSet {
212156 name : String ,
213157 class : & ' static Py < PyType > ,
214158 getter : Option < PyGetterFunc > ,
215159 setter : Option < PySetterFunc > ,
216- deleter : Option < PyDeleterFunc > ,
217160 // doc: Option<String>,
218161}
219162
@@ -273,7 +216,6 @@ impl PyGetSet {
273216 class,
274217 getter : None ,
275218 setter : None ,
276- deleter : None ,
277219 }
278220 }
279221
@@ -292,14 +234,6 @@ impl PyGetSet {
292234 self . setter = Some ( setter. into_setter ( ) ) ;
293235 self
294236 }
295-
296- pub fn with_delete < S , X > ( mut self , setter : S ) -> Self
297- where
298- S : IntoPyDeleterFunc < X > ,
299- {
300- self . deleter = Some ( setter. into_deleter ( ) ) ;
301- self
302- }
303237}
304238
305239#[ pyimpl( with( GetDescriptor , Constructor ) ) ]
@@ -314,29 +248,14 @@ impl PyGetSet {
314248 vm : & VirtualMachine ,
315249 ) -> PyResult < ( ) > {
316250 let zelf = PyRef :: < Self > :: try_from_object ( vm, zelf) ?;
317- match value {
318- Some ( value) => {
319- if let Some ( ref f) = zelf. setter {
320- f ( vm, obj, value)
321- } else {
322- Err ( vm. new_attribute_error ( format ! (
323- "attribute '{}' of '{}' objects is not writable" ,
324- zelf. name,
325- obj. class( ) . name( )
326- ) ) )
327- }
328- }
329- None => {
330- if let Some ( ref f) = zelf. deleter {
331- f ( vm, obj)
332- } else {
333- Err ( vm. new_attribute_error ( format ! (
334- "attribute '{}' of '{}' objects is not writable" ,
335- zelf. name,
336- obj. class( ) . name( )
337- ) ) )
338- }
339- }
251+ if let Some ( ref f) = zelf. setter {
252+ f ( vm, obj, value. unwrap_or_else ( || vm. ctx . none ( ) ) )
253+ } else {
254+ Err ( vm. new_attribute_error ( format ! (
255+ "attribute '{}' of '{}' objects is not writable" ,
256+ zelf. name,
257+ obj. class( ) . name( )
258+ ) ) )
340259 }
341260 }
342261 #[ pymethod]
0 commit comments