From bbd2c5b990a5f22ba097fab0239f1a49f14f22b4 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Sat, 21 Dec 2024 13:51:44 +0100 Subject: [PATCH] address _psosx.py --- psutil/__init__.py | 4 ++-- psutil/_pslinux.py | 4 ++-- psutil/_psosx.py | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/psutil/__init__.py b/psutil/__init__.py index 46f2d3643..e3c8da847 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -1270,8 +1270,8 @@ def _send_signal(self, sig): else: self._gone = True raise NoSuchProcess(self.pid, self._name) from e - except PermissionError: - raise AccessDenied(self.pid, self._name) + except PermissionError as e: + raise AccessDenied(self.pid, self._name) from e def send_signal(self, sig): """Send a signal *sig* to process pre-emptively checking diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index d5ac74aff..6e02bd5f6 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -867,7 +867,7 @@ def decode_address(addr, family): socket.AF_INET6, struct.pack('<4I', *struct.unpack('<4I', ip)), ) - except ValueError as err: + except ValueError: # see: https://github.com/giampaolo/psutil/issues/623 if not supports_ipv6(): raise _Ipv6UnsupportedError from None @@ -892,7 +892,7 @@ def process_inet(file, family, type_, inodes, filter_pid=None): f"error while parsing {file}; malformed line" f" {lineno} {line!r}" ) - raise RuntimeError(msg) + raise RuntimeError(msg) from None if inode in inodes: # # We assume inet sockets are unique, so we error # # out if there are multiple references to the diff --git a/psutil/_psosx.py b/psutil/_psosx.py index 3fdbcd6d7..57012346a 100644 --- a/psutil/_psosx.py +++ b/psutil/_psosx.py @@ -345,13 +345,13 @@ def wrap_exceptions(fun): def wrapper(self, *args, **kwargs): try: return fun(self, *args, **kwargs) - except ProcessLookupError: + except ProcessLookupError as e: if is_zombie(self.pid): - raise ZombieProcess(self.pid, self._name, self._ppid) + raise ZombieProcess(self.pid, self._name, self._ppid) from e else: - raise NoSuchProcess(self.pid, self._name) - except PermissionError: - raise AccessDenied(self.pid, self._name) + raise NoSuchProcess(self.pid, self._name) from e + except PermissionError as e: + raise AccessDenied(self.pid, self._name) from e return wrapper