The easiest way to do this is to convert str inputs for interface_dir to pathlib.Path. importlib.resources.abc.Traversable is a subset of pathlib.Path.
|
self.interface_dir = interface_dir |
if isinstance(interface_dir, str):
interface_dir = Path(interface_dir)
self.interface_dir = interface_dir
This would narrow the type of self.interface_dir to pathlib.Path | importlib.resources.abc.Traversable, which both implement joinpath and read_text.
|
def _add_interface(self, filename, handler): |
|
if not os.path.isabs(filename): |
|
filename = os.path.join(self.interface_dir, filename + ".varlink") |
|
|
|
with open(filename) as f: |
|
interface = Interface(f.read()) |
|
self.interfaces[interface.name] = interface |
|
self.interfaces_handlers[interface.name] = handler |
def _add_interface(self, filename, handler):
filepath = Path(filename)
if not filepath.is_absolute():
filepath = self.interface_dir.joinpath(filename + ".varlink")
interface = Interface(filepath.read_text())
self.interfaces[interface.name] = interface
self.interfaces_handlers[interface.name] = handler
The easiest way to do this is to convert
strinputs forinterface_dirtopathlib.Path.importlib.resources.abc.Traversableis a subset ofpathlib.Path.python/varlink/server.py
Line 75 in 70735a7
This would narrow the type of
self.interface_dirtopathlib.Path | importlib.resources.abc.Traversable, which both implementjoinpathandread_text.python/varlink/server.py
Lines 260 to 267 in 70735a7