From 73c4152bb5c6d9b48d88c080411adab87eea4e7c Mon Sep 17 00:00:00 2001 From: Leonard de Ruijter Date: Sat, 14 Dec 2024 18:51:35 +0100 Subject: [PATCH] Improve typing --- source/hwPortUtils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source/hwPortUtils.py b/source/hwPortUtils.py index 3653db4bd5..fe3bc32da5 100644 --- a/source/hwPortUtils.py +++ b/source/hwPortUtils.py @@ -42,6 +42,7 @@ def __str__(self): PSP_DEVINFO_DATA = ctypes.POINTER(SP_DEVINFO_DATA) +DeviceInfoT = dict[str, str | None] class SP_DEVICE_INTERFACE_DATA(ctypes.Structure): @@ -159,7 +160,7 @@ def _isDebug(): return config.conf["debugLog"]["hwIo"] -def _getBluetoothPortInfo(regKey: int, hwID: str) -> dict: +def _getBluetoothPortInfo(regKey: int, hwID: str) -> DeviceInfoT: info = {} try: port = info["port"] = winreg.QueryValueEx(regKey, "PortName")[0] @@ -210,7 +211,7 @@ def _getBluetoothPortInfo(regKey: int, hwID: str) -> dict: return info -def listComPorts(onlyAvailable: bool = True) -> typing.Iterator[dict]: +def listComPorts(onlyAvailable: bool = True) -> typing.Iterator[DeviceInfoT]: """List com ports on the system. :param onlyAvailable: Only return ports that are currently available. :return: Dicts including keys of port, friendlyName and hardwareID. @@ -429,7 +430,7 @@ def __str__(self): SetupDiDestroyDeviceInfoList(g_hdi) -def listUsbDevices(onlyAvailable: bool = True) -> typing.Iterator[dict]: +def listUsbDevices(onlyAvailable: bool = True) -> typing.Iterator[DeviceInfoT]: """List USB devices on the system. :param onlyAvailable: Only return devices that are currently available. :return: Generates dicts including keys of usbID (VID and PID), devicePath and hardwareID. @@ -497,10 +498,10 @@ def __init__(self, **kwargs): super().__init__(Size=ctypes.sizeof(HIDD_ATTRIBUTES), **kwargs) -_getHidInfoCache: dict[str, dict] = {} +_getHidInfoCache: dict[str, DeviceInfoT] = {} -def _getHidInfo(hwId: str, path: str) -> dict[str, str | None]: +def _getHidInfo(hwId: str, path: str) -> DeviceInfoT: info = { "hardwareID": hwId, "devicePath": path, @@ -576,7 +577,7 @@ def _getHidInfo(hwId: str, path: str) -> dict[str, str | None]: _hidGuid = None -def listHidDevices(onlyAvailable: bool = True) -> typing.Iterator[dict]: +def listHidDevices(onlyAvailable: bool = True) -> typing.Iterator[DeviceInfoT]: """List HID devices on the system. @param onlyAvailable: Only return devices that are currently available. @return: Generates dicts including keys such as hardwareID,