Skip to content

Commit

Permalink
satisfy mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Wiggins authored and Roy Wiggins committed Apr 5, 2024
1 parent c99181d commit e77ff01
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
14 changes: 2 additions & 12 deletions common/rule_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

# Standard python includes
from typing import Any, Dict, Optional, Union
from typing import Any, Dict, Optional, Tuple, Union
import daiquiri

# App-specific includes
Expand Down Expand Up @@ -65,7 +65,7 @@ def eval_rule(rule: str, tags: Dict[str, str]) -> Any:
logger.info(f"Result: {result}")
return result

def parse_rule(rule: str, tags: Dict[str, str]) -> tuple[bool,Optional[str], Optional[str]]:
def parse_rule(rule: str, tags: Dict[str, str]) -> Tuple[bool,Optional[str], Optional[str]]:
try:
result = eval_rule(rule, tags)
return True if result else False, result, None
Expand All @@ -77,16 +77,6 @@ def parse_rule(rule: str, tags: Dict[str, str]) -> tuple[bool,Optional[str], Opt
) # handle_error
return False, None, str(e)


def test_rule(rule: str, tags: Dict[str, str]) -> str:
"""Tests the given rule for validity using the given tags dictionary. Similar to parse_rule but with
more diagnostic output format for the testing dialog. Also warns about invalid tags."""
try:
result = eval_rule(rule, tags)
return result
except TagNotFoundException as e:
return str(e)

def test_completion_series(value: str) -> str:
"""Tests if the given string with the list of series required for study completion has valid format. If so, True
is returned as string, otherwise the error description is returned."""
Expand Down
2 changes: 1 addition & 1 deletion common/tags_rule_interface.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Tags:
def __init__(self, input_dict):
def __init__(self, input_dict) -> None:
self._dict = input_dict

def __getattr__(self, name):
Expand Down
7 changes: 4 additions & 3 deletions routing/route_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ def route_series(task_id: str, series_UID: str) -> None:

tagsList_encoding_error = False
try:
tagsList: Dict[str, str] = {}
try:
with open(tagsMasterFile, "r", encoding="utf-8", errors="strict") as json_file:
tagsList: Dict[str, str] = json.load(json_file)
tagsList = json.load(json_file)
except UnicodeDecodeError:
with open(tagsMasterFile, "r", encoding="utf-8", errors="surrogateescape") as json_file:
tagsList: Dict[str, str] = json.load(json_file)
tagsList = json.load(json_file)
tagsList_encoding_error = True

except Exception:
Expand Down Expand Up @@ -173,7 +174,7 @@ def get_triggered_rules(


def push_series_complete(
task_id: str, file_list: List[str], series_UID: str, destination: str, discard_rule: str, copy_files: bool, *, tagsList_encoding_error
task_id: str, file_list: List[str], series_UID: str, destination: str, discard_rule: str, copy_files: bool, *, tagsList_encoding_error=False
) -> None:
"""
Moves all files of the series into either the "discard" or "success" folders, which both are periodically cleared.
Expand Down

0 comments on commit e77ff01

Please sign in to comment.