mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #2867 from sobolevn/pyproperty-cleanup
Cleans up `pyproperty` definitions
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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()))
|
||||
}
|
||||
|
||||
@@ -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()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user