diff --git a/src/pycanape/cnp_api/cnp_prototype.py b/src/pycanape/cnp_api/cnp_prototype.py index fa99e29..70c867b 100644 --- a/src/pycanape/cnp_api/cnp_prototype.py +++ b/src/pycanape/cnp_api/cnp_prototype.py @@ -1109,8 +1109,8 @@ def _get_last_error(self, result, function, args): if error_code > 0: error_msg = ( - f"{cnp_constants.ErrorCodes(error_code).name}: " - f"{ptr.contents.value.decode('ascii')}" # type: ignore[union-attr] + f"{cnp_constants.ErrorCodes(error_code).name}: " # type: ignore[union-attr] + f"{ptr.contents.value.decode('ascii')}" ) raise CANapeError(error_code, error_msg, function.__name__) return args diff --git a/src/pycanape/utils.py b/src/pycanape/utils.py index 704e517..fa475aa 100644 --- a/src/pycanape/utils.py +++ b/src/pycanape/utils.py @@ -9,7 +9,7 @@ from ctypes.util import find_library from enum import Enum from pathlib import Path -from typing import List +from typing import List, Optional import psutil @@ -61,13 +61,14 @@ def get_canape_versions() -> List[CANapeVersion]: if not re.match(r"Path\d{3}", name): continue try: - versions.append(CANapeVersion(name.removeprefix("Path")[:2])) + version_number = re.sub(pattern=r"Path", repl="", string=name) + versions.append(CANapeVersion(version_number[:2])) except ValueError: continue return versions -def get_canape_path(version: CANapeVersion | None = None) -> Path: +def get_canape_path(version: Optional[CANapeVersion] = None) -> Path: """Return the path to the CANape installation from Windows registry. :param version: @@ -85,7 +86,7 @@ def get_canape_path(version: CANapeVersion | None = None) -> Path: raise FileNotFoundError(err_msg) from None -def get_canape_data_path(version: CANapeVersion | None = None) -> Path: +def get_canape_data_path(version: Optional[CANapeVersion] = None) -> Path: """Return the path to the CANape data folder from Windows registry. :param version: @@ -103,7 +104,7 @@ def get_canape_data_path(version: CANapeVersion | None = None) -> Path: raise FileNotFoundError(err_msg) from None -def get_canape_dll_path(version: CANapeVersion | None = None) -> Path: +def get_canape_dll_path(version: Optional[CANapeVersion] = None) -> Path: """Return the path to the CANapAPI.dll from Windows registry or PATH. :param version: