Convert to OsPath only (no fd support)
(
&self,
obj: PyObjectRef,
allow_fd: bool,
vm: &VirtualMachine,
)
| 104 | |
| 105 | /// Convert to OsPath only (no fd support) |
| 106 | fn try_path_inner( |
| 107 | &self, |
| 108 | obj: PyObjectRef, |
| 109 | allow_fd: bool, |
| 110 | vm: &VirtualMachine, |
| 111 | ) -> PyResult<OsPath> { |
| 112 | // Try direct str/bytes match |
| 113 | let obj = match self.try_match_str_bytes(obj.clone(), vm)? { |
| 114 | Ok(path) => return Ok(path), |
| 115 | Err(obj) => obj, |
| 116 | }; |
| 117 | |
| 118 | // Call __fspath__ |
| 119 | let type_error_msg = || self.type_error_msg(&obj.class().name(), allow_fd); |
| 120 | let method = |
| 121 | vm.get_method_or_type_error(obj.clone(), identifier!(vm, __fspath__), type_error_msg)?; |
| 122 | if vm.is_none(&method) { |
| 123 | return Err(vm.new_type_error(type_error_msg())); |
| 124 | } |
| 125 | let result = method.call((), vm)?; |
| 126 | |
| 127 | // Match __fspath__ result |
| 128 | self.try_match_str_bytes(result.clone(), vm)?.map_err(|_| { |
| 129 | vm.new_type_error(format!( |
| 130 | "{}expected {}.__fspath__() to return str or bytes, not {}", |
| 131 | self.error_prefix(), |
| 132 | obj.class().name(), |
| 133 | result.class().name(), |
| 134 | )) |
| 135 | }) |
| 136 | } |
| 137 | |
| 138 | /// Try to match str or bytes, returns Err(obj) if neither |
| 139 | fn try_match_str_bytes( |
no test coverage detected