Skip to content

Commit 3dd94a7

Browse files
jellybehrmann
authored andcommitted
varlink: further type the client class
1 parent 9f5debf commit 3dd94a7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

varlink/client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010
import tempfile
1111
import threading
12+
from typing import Optional
1213

1314
from .error import InterfaceNotFound, VarlinkEncoder, VarlinkError
1415
from .scanner import Interface, _Method
@@ -443,7 +444,7 @@ def new_bridge_socket():
443444
self._child_pid = p.pid
444445
return sp[0]
445446

446-
def new_bridge_socket_compat():
447+
def new_bridge_socket_compat() -> socket.socket:
447448
sp = socket.socketpair()
448449
p = subprocess.Popen(
449450
" ".join(argv), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True
@@ -563,7 +564,9 @@ def cleanup(self) -> None:
563564
except Exception: # TODO: maybe just ChildProcessError?
564565
pass
565566

566-
def open(self, interface_name, namespaced=False, connection=None):
567+
def open(
568+
self, interface_name: str, namespaced: bool = False, connection: Optional[socket.socket] = None
569+
) -> SimpleClientInterfaceHandler:
567570
"""Open a new connection and get a client interface handle with the varlink methods installed.
568571
569572
:param interface_name: an interface name, which the service this client object is
@@ -586,11 +589,12 @@ def open(self, interface_name, namespaced=False, connection=None):
586589

587590
return self.handler(self._interfaces[interface_name], connection, namespaced=namespaced)
588591

589-
def open_connection(self):
592+
def open_connection(self) -> socket.socket:
590593
"""Open a new connection and return the socket.
591594
:exception OSError: anything socket.connect() throws
592595
593596
"""
597+
assert self._socket_fn, "socket_fn not initialised"
594598
return self._socket_fn()
595599

596600
def get_interfaces(self, socket_connection=None):
@@ -628,7 +632,7 @@ def get_interface(self, interface_name, socket_connection=None):
628632

629633
return interface
630634

631-
def add_interface(self, interface):
635+
def add_interface(self, interface: Interface) -> None:
632636
"""Manually add or overwrite an interface definition from an Interface object.
633637
634638
:param interface: an Interface() object

0 commit comments

Comments
 (0)