Skip to content

Commit 24d60e9

Browse files
committed
fix: change assert_never to runtim errors
1 parent a8edcf7 commit 24d60e9

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

dissect/target/helpers/nfs/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __exit__(self, _: type[BaseException] | None, __: BaseException | None, ___:
5353
return False # Reraise exceptions
5454

5555
@classmethod
56-
def connect(cls, hostname: str, port: int, auth: AuthScheme[Credentials, Verifier], local_port: int) -> "Client":
56+
def connect(cls, hostname: str, port: int, auth: AuthScheme[Credentials, Verifier], local_port: int) -> Client:
5757
rpc_client = SunRpcClient.connect(hostname, port, auth, local_port)
5858
return Client(rpc_client)
5959

dissect/target/helpers/sunrpc/client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ class Client(AbstractContextManager, Generic[Credentials, Verifier]):
6767
PMAP_PORT = 111
6868

6969
@classmethod
70-
def connect_port_mapper(cls, hostname: str) -> "Client":
70+
def connect_port_mapper(cls, hostname: str) -> Client:
7171
return cls.connect(hostname, cls.PMAP_PORT, auth_null())
7272

7373
@classmethod
74-
def connect(
75-
cls, hostname: str, port: int, auth: AuthScheme[Credentials, Verifier], local_port: int = 0
76-
) -> "Client":
74+
def connect(cls, hostname: str, port: int, auth: AuthScheme[Credentials, Verifier], local_port: int = 0) -> Client:
7775
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7876
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
7977
sock.bind(("", local_port))

dissect/target/helpers/sunrpc/serializer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io
44
from abc import ABC, abstractmethod
55
from enum import IntEnum
6-
from typing import Generic, Type, TypeVar, assert_never
6+
from typing import Generic, Type, TypeVar
77

88
from dissect.target.helpers.sunrpc import sunrpc
99

@@ -254,7 +254,8 @@ def deserialize(
254254
elif reply_stat == ReplyStat.MSG_DENIED:
255255
reply = self._read_rejected_reply(payload)
256256
else:
257-
assert_never(reply_stat)
257+
# assert_never is slightly better, but only available starting from Python 3.11
258+
raise ValueError(f"Unexpected value for reply_stat {reply_stat}")
258259

259260
return sunrpc.Message(xid, reply)
260261

@@ -290,7 +291,8 @@ def _read_rejected_reply(self, payload: io.BytesIO) -> sunrpc.RejectedReply:
290291
auth_stat = self._read_enum(payload, sunrpc.AuthStat)
291292
return sunrpc.RejectedReply(reject_stat, auth_stat)
292293
else:
293-
assert_never(reject_stat)
294+
# assert_never is slightly better, but only available starting from Python 3.11
295+
raise ValueError(f"Unexpected value for reject_stat: {reject_stat}")
294296

295297
def _read_mismatch(self, payload: io.BytesIO) -> sunrpc.Mismatch:
296298
low = self._read_uint32(payload)

0 commit comments

Comments
 (0)