(vm: &VirtualMachine, obj: PyObjectRef)
| 160 | |
| 161 | impl<T: PyPayload> TryFromObject for PyRefExact<T> { |
| 162 | fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> { |
| 163 | let target_cls = T::class(&vm.ctx); |
| 164 | let cls = obj.class(); |
| 165 | if cls.is(target_cls) { |
| 166 | let obj = obj |
| 167 | .downcast() |
| 168 | .map_err(|obj| vm.new_downcast_runtime_error(target_cls, &obj))?; |
| 169 | Ok(Self { inner: obj }) |
| 170 | } else if cls.fast_issubclass(target_cls) { |
| 171 | Err(vm.new_type_error(format!( |
| 172 | "Expected an exact instance of '{}', not a subclass '{}'", |
| 173 | target_cls.name(), |
| 174 | cls.name(), |
| 175 | ))) |
| 176 | } else { |
| 177 | Err(vm.new_type_error(format!( |
| 178 | "Expected type '{}', not '{}'", |
| 179 | target_cls.name(), |
| 180 | cls.name(), |
| 181 | ))) |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | impl<T: PyPayload> Deref for PyRefExact<T> { |
nothing calls this directly
no test coverage detected