diff --git a/stdlib/src/socket.rs b/stdlib/src/socket.rs index 7a0e51722..4c0227d5c 100644 --- a/stdlib/src/socket.rs +++ b/stdlib/src/socket.rs @@ -372,7 +372,7 @@ mod _socket { addr: PyObjectRef, caller: &str, vm: &VirtualMachine, - ) -> PyResult { + ) -> Result { let family = self.family.load(); match family { #[cfg(unix)] @@ -550,7 +550,7 @@ mod _socket { zelf: PyRef, (family, socket_kind, proto, fileno): ::Args, vm: &VirtualMachine, - ) -> PyResult<(), IoOrPyException> { + ) -> Result<(), IoOrPyException> { let mut family = family.unwrap_or(-1); let mut socket_kind = socket_kind.unwrap_or(-1); let mut proto = proto.unwrap_or(-1); @@ -629,7 +629,7 @@ mod _socket { &self, address: PyObjectRef, vm: &VirtualMachine, - ) -> PyResult<(), IoOrPyException> { + ) -> Result<(), IoOrPyException> { self.connect_inner(address, "connect", vm) } @@ -642,13 +642,13 @@ mod _socket { } #[pymethod] - fn bind(&self, address: PyObjectRef, vm: &VirtualMachine) -> PyResult<(), IoOrPyException> { + fn bind(&self, address: PyObjectRef, vm: &VirtualMachine) -> Result<(), IoOrPyException> { let sock_addr = self.extract_address(address, "bind", vm)?; Ok(self.sock()?.bind(&sock_addr)?) } #[pymethod] - fn listen(&self, backlog: OptionalArg) -> PyResult<(), io::Error> { + fn listen(&self, backlog: OptionalArg) -> io::Result<()> { let backlog = backlog.unwrap_or(128); let backlog = if backlog < 0 { 0 } else { backlog }; self.sock()?.listen(backlog) @@ -658,7 +658,7 @@ mod _socket { fn _accept( &self, vm: &VirtualMachine, - ) -> PyResult<(RawSocket, PyObjectRef), IoOrPyException> { + ) -> Result<(RawSocket, PyObjectRef), IoOrPyException> { let (sock, addr) = self.sock_op(vm, SelectKind::Read, || self.sock()?.accept())?; let fd = into_sock_fileno(sock); Ok((fd, get_addr_tuple(&addr, vm))) @@ -670,7 +670,7 @@ mod _socket { bufsize: usize, flags: OptionalArg, vm: &VirtualMachine, - ) -> PyResult, IoOrPyException> { + ) -> Result, IoOrPyException> { let flags = flags.unwrap_or(0); let mut buffer = Vec::with_capacity(bufsize); let sock = self.sock()?; @@ -687,7 +687,7 @@ mod _socket { buf: ArgMemoryBuffer, flags: OptionalArg, vm: &VirtualMachine, - ) -> PyResult { + ) -> Result { let flags = flags.unwrap_or(0); let sock = self.sock()?; let mut buf = buf.borrow_buf_mut(); @@ -703,7 +703,7 @@ mod _socket { bufsize: isize, flags: OptionalArg, vm: &VirtualMachine, - ) -> PyResult<(Vec, PyObjectRef), IoOrPyException> { + ) -> Result<(Vec, PyObjectRef), IoOrPyException> { let flags = flags.unwrap_or(0); let bufsize = bufsize .to_usize() @@ -724,7 +724,7 @@ mod _socket { nbytes: OptionalArg, flags: OptionalArg, vm: &VirtualMachine, - ) -> PyResult<(usize, PyObjectRef), IoOrPyException> { + ) -> Result<(usize, PyObjectRef), IoOrPyException> { let mut buf = buf.borrow_buf_mut(); let buf = &mut *buf; let buf = match nbytes { @@ -754,7 +754,7 @@ mod _socket { bytes: ArgBytesLike, flags: OptionalArg, vm: &VirtualMachine, - ) -> PyResult { + ) -> Result { let flags = flags.unwrap_or(0); let buf = bytes.borrow_buf(); let buf = &*buf; @@ -769,7 +769,7 @@ mod _socket { bytes: ArgBytesLike, flags: OptionalArg, vm: &VirtualMachine, - ) -> PyResult<(), IoOrPyException> { + ) -> Result<(), IoOrPyException> { let flags = flags.unwrap_or(0); let timeout = self.get_timeout().ok(); @@ -799,7 +799,7 @@ mod _socket { arg2: PyObjectRef, arg3: OptionalArg, vm: &VirtualMachine, - ) -> PyResult { + ) -> Result { // signature is bytes[, flags], address let (flags, address) = match arg3 { OptionalArg::Present(arg3) => { @@ -966,7 +966,7 @@ mod _socket { } #[pymethod] - fn shutdown(&self, how: i32, vm: &VirtualMachine) -> PyResult<(), IoOrPyException> { + fn shutdown(&self, how: i32, vm: &VirtualMachine) -> Result<(), IoOrPyException> { let how = match how { c::SHUT_RD => Shutdown::Read, c::SHUT_WR => Shutdown::Write, @@ -1113,7 +1113,7 @@ mod _socket { #[cfg(all(unix, not(target_os = "redox")))] #[pyfunction] - fn sethostname(hostname: PyStrRef) -> PyResult<(), nix::errno::Errno> { + fn sethostname(hostname: PyStrRef) -> nix::Result<()> { nix::unistd::sethostname(hostname.as_str()) } @@ -1315,7 +1315,7 @@ mod _socket { fn getaddrinfo( opts: GAIOptions, vm: &VirtualMachine, - ) -> PyResult, IoOrPyException> { + ) -> Result, IoOrPyException> { let hints = dns_lookup::AddrInfoHints { socktype: opts.ty, protocol: opts.proto, @@ -1356,7 +1356,7 @@ mod _socket { fn gethostbyaddr( addr: PyStrRef, vm: &VirtualMachine, - ) -> PyResult<(String, PyListRef, PyListRef), IoOrPyException> { + ) -> Result<(String, PyListRef, PyListRef), IoOrPyException> { let addr = get_addr(vm, addr, c::AF_UNSPEC)?; let (hostname, _) = dns_lookup::getnameinfo(&addr, 0) .map_err(|e| convert_socket_error(vm, e, SocketError::HError))?; @@ -1369,7 +1369,7 @@ mod _socket { } #[pyfunction] - fn gethostbyname(name: PyStrRef, vm: &VirtualMachine) -> PyResult { + fn gethostbyname(name: PyStrRef, vm: &VirtualMachine) -> Result { let addr = get_addr(vm, name, c::AF_INET)?; match addr { SocketAddr::V4(ip) => Ok(ip.ip().to_string()), @@ -1381,7 +1381,7 @@ mod _socket { fn gethostbyname_ex( name: PyStrRef, vm: &VirtualMachine, - ) -> PyResult<(String, PyListRef, PyListRef), IoOrPyException> { + ) -> Result<(String, PyListRef, PyListRef), IoOrPyException> { let addr = get_addr(vm, name, c::AF_UNSPEC)?; let (hostname, _) = dns_lookup::getnameinfo(&addr, 0) .map_err(|e| convert_socket_error(vm, e, SocketError::HError))?; @@ -1450,7 +1450,7 @@ mod _socket { address: PyTupleRef, flags: i32, vm: &VirtualMachine, - ) -> PyResult<(String, String), IoOrPyException> { + ) -> Result<(String, String), IoOrPyException> { match address.len() { 2 | 3 | 4 => {} _ => { @@ -1500,7 +1500,7 @@ mod _socket { family: OptionalArg, socket_kind: OptionalArg, proto: OptionalArg, - ) -> PyResult<(PySocket, PySocket), IoOrPyException> { + ) -> Result<(PySocket, PySocket), IoOrPyException> { let family = family.unwrap_or(libc::AF_UNIX); let socket_kind = socket_kind.unwrap_or(libc::SOCK_STREAM); let proto = proto.unwrap_or(0); @@ -1685,7 +1685,7 @@ mod _socket { vm: &VirtualMachine, pyname: PyStrRef, af: i32, - ) -> PyResult { + ) -> Result { let name = pyname.as_str(); if name.is_empty() { let hints = dns_lookup::AddrInfoHints { @@ -1897,7 +1897,7 @@ mod _socket { } #[pyfunction] - fn dup(x: PyObjectRef, vm: &VirtualMachine) -> PyResult { + fn dup(x: PyObjectRef, vm: &VirtualMachine) -> Result { let sock = get_raw_sock(x, vm)?; let sock = std::mem::ManuallyDrop::new(sock_from_raw(sock, vm)?); let newsock = sock.try_clone()?; @@ -1908,7 +1908,7 @@ mod _socket { } #[pyfunction] - fn close(x: PyObjectRef, vm: &VirtualMachine) -> PyResult<(), IoOrPyException> { + fn close(x: PyObjectRef, vm: &VirtualMachine) -> Result<(), IoOrPyException> { Ok(close_inner(get_raw_sock(x, vm)?)?) } diff --git a/vm/src/object/ext.rs b/vm/src/object/ext.rs index 957ec3faa..47b7b91d6 100644 --- a/vm/src/object/ext.rs +++ b/vm/src/object/ext.rs @@ -27,7 +27,7 @@ Basically reference counting, but then done by rust. /// Use this type for functions which return a python object or an exception. /// Both the python object and the python exception are `PyObjectRef` types /// since exceptions are also python objects. -pub type PyResult = Result; // A valid value, or an exception +pub type PyResult = Result; // A valid value, or an exception // TODO: remove these 2 impls impl fmt::Display for PyObjectRef { @@ -366,7 +366,7 @@ where } } -impl ToPyResult for PyResult +impl ToPyResult for Result where T: ToPyObject, E: ToPyException,