|
1 |
| -use super::objproperty::PyPropertyRef; |
2 |
| -use super::objstr::PyStringRef; |
3 | 1 | use super::objtype::PyClassRef;
|
4 | 2 | use crate::pyobject::{
|
5 |
| - IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, |
6 |
| - TypeProtocol, |
| 3 | + IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, |
7 | 4 | };
|
8 | 5 | use crate::vm::VirtualMachine;
|
9 | 6 |
|
@@ -52,66 +49,6 @@ impl PyNone {
|
52 | 49 | Ok(false)
|
53 | 50 | }
|
54 | 51 |
|
55 |
| - #[pymethod(name = "__getattribute__")] |
56 |
| - fn get_attribute(zelf: PyRef<Self>, name: PyStringRef, vm: &VirtualMachine) -> PyResult { |
57 |
| - vm_trace!("None.__getattribute__({:?}, {:?})", self, name); |
58 |
| - let cls = zelf.class(); |
59 |
| - |
60 |
| - // Properties use a comparision with None to determine if they are either invoked by am |
61 |
| - // instance binding or a class binding. But if the object itself is None then this detection |
62 |
| - // won't work. Instead we call a special function on property that bypasses this check, as |
63 |
| - // we are invoking it as a instance binding. |
64 |
| - // |
65 |
| - // In CPython they instead call the slot tp_descr_get with NULL to indicates it's an |
66 |
| - // instance binding. |
67 |
| - // https://github.com/python/cpython/blob/master/Objects/typeobject.c#L3281 |
68 |
| - fn call_descriptor( |
69 |
| - descriptor: PyObjectRef, |
70 |
| - get_func: PyObjectRef, |
71 |
| - obj: PyObjectRef, |
72 |
| - cls: PyObjectRef, |
73 |
| - vm: &VirtualMachine, |
74 |
| - ) -> PyResult { |
75 |
| - if let Ok(property) = PyPropertyRef::try_from_object(vm, descriptor.clone()) { |
76 |
| - property.instance_binding_get(obj, vm) |
77 |
| - } else { |
78 |
| - vm.invoke(&get_func, vec![descriptor, obj, cls]) |
79 |
| - } |
80 |
| - } |
81 |
| - |
82 |
| - if let Some(attr) = cls.get_attr(name.as_str()) { |
83 |
| - let attr_class = attr.class(); |
84 |
| - if attr_class.has_attr("__set__") { |
85 |
| - if let Some(get_func) = attr_class.get_attr("__get__") { |
86 |
| - return call_descriptor( |
87 |
| - attr, |
88 |
| - get_func, |
89 |
| - zelf.into_object(), |
90 |
| - cls.into_object(), |
91 |
| - vm, |
92 |
| - ); |
93 |
| - } |
94 |
| - } |
95 |
| - } |
96 |
| - |
97 |
| - // None has no attributes and cannot have attributes set on it. |
98 |
| - // if let Some(obj_attr) = zelf.as_object().get_attr(name.as_str()) { |
99 |
| - // Ok(obj_attr) |
100 |
| - // } else |
101 |
| - if let Some(attr) = cls.get_attr(name.as_str()) { |
102 |
| - let attr_class = attr.class(); |
103 |
| - if let Some(get_func) = attr_class.get_attr("__get__") { |
104 |
| - call_descriptor(attr, get_func, zelf.into_object(), cls.into_object(), vm) |
105 |
| - } else { |
106 |
| - Ok(attr) |
107 |
| - } |
108 |
| - } else if let Some(getter) = cls.get_attr("__getattr__") { |
109 |
| - vm.invoke(&getter, vec![zelf.into_object(), name.into_object()]) |
110 |
| - } else { |
111 |
| - Err(vm.new_attribute_error(format!("{} has no attribute '{}'", zelf.as_object(), name))) |
112 |
| - } |
113 |
| - } |
114 |
| - |
115 | 52 | #[pymethod(name = "__eq__")]
|
116 | 53 | fn eq(&self, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
117 | 54 | if vm.is_none(&rhs) {
|
|
0 commit comments