Skip to content

Commit c0d850b

Browse files
committed
Obsolete PyGetSet.deleter
1 parent 2e77581 commit c0d850b

File tree

3 files changed

+16
-95
lines changed

3 files changed

+16
-95
lines changed

vm/src/builtins/function.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,6 @@ impl PyCell {
620620
fn set_cell_contents(&self, x: PyObjectRef) {
621621
self.set(Some(x))
622622
}
623-
#[pyproperty(deleter)]
624-
fn del_cell_contents(&self) {
625-
self.set(None)
626-
}
627623
}
628624

629625
pub fn init(context: &Context) {

vm/src/builtins/getset.rs

Lines changed: 8 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::{
1414
pub type PyGetterFunc = Box<py_dyn_fn!(dyn Fn(&VirtualMachine, PyObjectRef) -> PyResult)>;
1515
pub 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

1918
pub 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")]
211155
pub 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]

vm/src/stdlib/io.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,9 +2312,15 @@ mod _io {
23122312
}
23132313

23142314
#[pyproperty(setter, name = "_CHUNK_SIZE")]
2315-
fn set_chunksize(&self, chunk_size: usize, vm: &VirtualMachine) -> PyResult<()> {
2315+
fn set_chunksize(&self, chunk_size: Option<usize>, vm: &VirtualMachine) -> PyResult<()> {
23162316
let mut textio = self.lock(vm)?;
2317-
textio.chunk_size = chunk_size;
2317+
match chunk_size {
2318+
Some(chunk_size) => textio.chunk_size = chunk_size,
2319+
None => Err(vm.new_attribute_error("cannot delete attribute".to_owned()))?,
2320+
};
2321+
// TODO: RUSTPYTHON
2322+
// Change chunk_size type, validate it manually and throws ValueError if invalid.
2323+
// https://github.com/python/cpython/blob/2e9da8e3522764d09f1d6054a2be567e91a30812/Modules/_io/textio.c#L3124-L3143
23182324
Ok(())
23192325
}
23202326

0 commit comments

Comments
 (0)