Skip to content

Commit

Permalink
fix python 3.8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
zariiii9003 committed Oct 17, 2023
1 parent 19e7ac4 commit 2058bef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/pycanape/cnp_api/cnp_prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/pycanape/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 2058bef

Please sign in to comment.