Merge pull request #2867 from sobolevn/pyproperty-cleanup

Cleans up `pyproperty` definitions
This commit is contained in:
Jim Fasarakis-Hilliard
2021-08-12 19:47:25 +03:00
committed by GitHub
7 changed files with 15 additions and 15 deletions

View File

@@ -61,7 +61,7 @@ impl PyClassMethod {
PyClassMethod { callable }.into_ref_with_type(vm, cls)
}
#[pyproperty(name = "__func__")]
#[pyproperty(magic)]
fn func(&self) -> PyObjectRef {
self.callable.clone()
}

View File

@@ -89,12 +89,12 @@ impl PyComplex {
self.value
}
#[pyproperty(name = "real")]
#[pyproperty]
fn real(&self) -> f64 {
self.value.re
}
#[pyproperty(name = "imag")]
#[pyproperty]
fn imag(&self) -> f64 {
self.value.im
}

View File

@@ -201,17 +201,17 @@ impl PyRange {
PyRange { start, stop, step }.into_ref_with_type(vm, cls)
}
#[pyproperty(name = "start")]
#[pyproperty]
fn start(&self) -> PyIntRef {
self.start.clone()
}
#[pyproperty(name = "stop")]
#[pyproperty]
fn stop(&self) -> PyIntRef {
self.stop.clone()
}
#[pyproperty(name = "step")]
#[pyproperty]
fn step(&self) -> PyIntRef {
self.step.clone()
}

View File

@@ -30,7 +30,7 @@ pub type PySliceRef = PyRef<PySlice>;
#[pyimpl(with(Hashable, Comparable))]
impl PySlice {
#[pyproperty(name = "start")]
#[pyproperty]
fn start(&self, vm: &VirtualMachine) -> PyObjectRef {
self.start.clone().into_pyobject(vm)
}
@@ -42,12 +42,12 @@ impl PySlice {
}
}
#[pyproperty(name = "stop")]
#[pyproperty]
fn stop(&self, _vm: &VirtualMachine) -> PyObjectRef {
self.stop.clone()
}
#[pyproperty(name = "step")]
#[pyproperty]
fn step(&self, vm: &VirtualMachine) -> PyObjectRef {
self.step.clone().into_pyobject(vm)
}

View File

@@ -89,7 +89,7 @@ impl PyBaseException {
Ok(())
}
#[pyproperty(name = "__traceback__")]
#[pyproperty(magic)]
pub fn traceback(&self) -> Option<PyTracebackRef> {
self.traceback.read().clone()
}
@@ -99,7 +99,7 @@ impl PyBaseException {
*self.traceback.write() = traceback;
}
#[pyproperty(name = "__cause__")]
#[pyproperty(magic)]
pub fn cause(&self) -> Option<PyBaseExceptionRef> {
self.cause.read().clone()
}
@@ -111,7 +111,7 @@ impl PyBaseException {
*c = cause;
}
#[pyproperty(name = "__context__")]
#[pyproperty(magic)]
pub fn context(&self) -> Option<PyBaseExceptionRef> {
self.context.read().clone()
}

View File

@@ -60,12 +60,12 @@ mod hashlib {
.into_object())
}
#[pyproperty(name = "name")]
#[pyproperty]
fn name(&self) -> String {
self.name.clone()
}
#[pyproperty(name = "digest_size")]
#[pyproperty]
fn digest_size(&self, vm: &VirtualMachine) -> PyResult {
Ok(vm.ctx.new_int(self.read().digest_size()))
}

View File

@@ -332,7 +332,7 @@ impl PyPattern {
self.sub(repl, text, vm)
}
#[pyproperty(name = "pattern")]
#[pyproperty]
fn pattern(&self, vm: &VirtualMachine) -> PyResult {
Ok(vm.ctx.new_str(self.pattern.clone()))
}