(vm: &VirtualMachine, obj: PyObjectRef)
| 68 | |
| 69 | impl TryFromObject for Fildes { |
| 70 | fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> { |
| 71 | use crate::builtins::int; |
| 72 | let int = match obj.downcast::<int::PyInt>() { |
| 73 | Ok(i) => i, |
| 74 | Err(obj) => { |
| 75 | let fileno_meth = vm.get_attribute_opt(obj, "fileno")?.ok_or_else(|| { |
| 76 | vm.new_type_error("argument must be an int, or have a fileno() method.") |
| 77 | })?; |
| 78 | fileno_meth |
| 79 | .call((), vm)? |
| 80 | .downcast() |
| 81 | .map_err(|_| vm.new_type_error("fileno() returned a non-integer"))? |
| 82 | } |
| 83 | }; |
| 84 | let fd = int.try_to_primitive(vm)?; |
| 85 | if fd < 0 { |
| 86 | return Err(vm.new_value_error(format!( |
| 87 | "file descriptor cannot be a negative integer ({fd})" |
| 88 | ))); |
| 89 | } |
| 90 | Ok(Self(fd)) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | #[cfg(unix)] |
nothing calls this directly
no test coverage detected