osbuild: fix optional-types
Optional types were provided in places but were not always correct. Add mypy checking and fix those that fail(ed).
This commit is contained in:
parent
6e66c69608
commit
3fd864e5a9
29 changed files with 209 additions and 111 deletions
|
|
@ -127,13 +127,20 @@ class Socket(contextlib.AbstractContextManager):
|
|||
@blocking.setter
|
||||
def blocking(self, value: bool):
|
||||
"""Set the blocking mode of the socket."""
|
||||
self._socket.setblocking(value)
|
||||
if self._socket:
|
||||
self._socket.setblocking(value)
|
||||
else:
|
||||
raise RuntimeError("Tried to set blocking mode without socket.")
|
||||
|
||||
def accept(self) -> Optional["Socket"]:
|
||||
"""Accept a new connection on the socket.
|
||||
|
||||
See python's `socket.accept` for more information.
|
||||
"""
|
||||
|
||||
if not self._socket:
|
||||
raise RuntimeError("Tried to accept without socket.")
|
||||
|
||||
# Since, in the kernel, for AF_UNIX, new connection requests,
|
||||
# i.e. clients connecting, are directly put on the receive
|
||||
# queue of the listener socket, accept here *should* always
|
||||
|
|
@ -151,6 +158,9 @@ class Socket(contextlib.AbstractContextManager):
|
|||
See python's `socket.listen` for details.
|
||||
"""
|
||||
|
||||
if not self._socket:
|
||||
raise RuntimeError("Tried to listen without socket.")
|
||||
|
||||
# `Socket.listen` accepts an `int` or no argument, but not `None`
|
||||
args = [backlog] if backlog is not None else []
|
||||
self._socket.listen(*args)
|
||||
|
|
@ -386,6 +396,9 @@ class Socket(contextlib.AbstractContextManager):
|
|||
If the payload cannot be serialized, a type error is raised.
|
||||
"""
|
||||
|
||||
if not self._socket:
|
||||
raise RuntimeError("Tried to send without socket.")
|
||||
|
||||
serialized = json.dumps(payload).encode()
|
||||
cmsg = []
|
||||
if fds:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue