Make property.__get__ owner parameter optional

This commit is contained in:
ben committed 2019-03-21 19:57:35 +13:00
1 parent a5f6a7b10d
commit 4ad8d5ed9b
2 files changed
+13 -4

No files matched your search

+1 -2
View File
@@ -51,8 +51,7 @@ assert type(null_property) is property
p = property(lambda x: x[0])
assert p.__get__((2,), tuple) == 2
# TODO owner parameter is optional
# assert p.__get__((2,)) == 2
assert p.__get__((2,)) == 2
with assertRaises(AttributeError):
null_property.__get__((), tuple)
+12 -2
View File
@@ -24,7 +24,12 @@ impl PyValue for PyReadOnlyProperty {
pub type PyReadOnlyPropertyRef = PyRef<PyReadOnlyProperty>;
impl PyReadOnlyPropertyRef {
fn get(self, obj: PyObjectRef, _owner: PyClassRef, vm: &mut VirtualMachine) -> PyResult {
fn get(
self,
obj: PyObjectRef,
_owner: OptionalArg<PyClassRef>,
vm: &mut VirtualMachine,
) -> PyResult {
if obj.is(&vm.ctx.none) {
Ok(self.into_object())
} else {
@@ -81,7 +86,12 @@ impl PyPropertyRef {
}
}
fn get(self, obj: PyObjectRef, _owner: PyClassRef, vm: &mut VirtualMachine) -> PyResult {
fn get(
self,
obj: PyObjectRef,
_owner: OptionalArg<PyClassRef>,
vm: &mut VirtualMachine,
) -> PyResult {
if let Some(getter) = self.getter.as_ref() {
if obj.is(&vm.ctx.none) {
Ok(self.into_object())