From 4b532ef92951d42fa04329e88d3a7c265b5bdd73 Mon Sep 17 00:00:00 2001 From: Harshad Khetpal Date: Tue, 18 Aug 2026 15:38:12 +0530 Subject: [PATCH] fix: avoid mutable default arguments and use identity check for type comparison Co-Authored-By: Claude Fable 5 --- src/tirith/core/core.py | 8 +++++--- src/tirith/core/evaluators/regex_match.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/tirith/core/core.py b/src/tirith/core/core.py index 0dfedaa5..00cde926 100644 --- a/src/tirith/core/core.py +++ b/src/tirith/core/core.py @@ -245,7 +245,7 @@ def final_evaluator(eval_string: str, eval_id_values: Dict[str, Optional[bool]]) def start_policy_evaluation( - policy_path: str, input_path: str, var_paths: List[str] = [], inline_vars: List[str] = [] + policy_path: str, input_path: str, var_paths: Optional[List[str]] = None, inline_vars: Optional[List[str]] = None ) -> Dict: """ Start Tirith policy evaluation from policy file, input file, and optional variable files. @@ -255,6 +255,8 @@ def start_policy_evaluation( :param var_paths: List of paths to the variable files :return: Policy evaluation result """ + var_paths = var_paths or [] + inline_vars = inline_vars or [] with open(policy_path) as f: policy_data = json.load(f) # TODO: validate policy_data against schema @@ -304,8 +306,8 @@ def _merge_var_dicts(var_dicts: List[dict]) -> dict: return merged_var_dict -def start_policy_evaluation_from_dict(policy_dict: Dict, input_dict: Dict, var_dict: Dict = {}) -> Dict: - policy_dict, not_found_vars = get_policy_with_vars_replaced(policy_dict, var_dict) +def start_policy_evaluation_from_dict(policy_dict: Dict, input_dict: Dict, var_dict: Optional[Dict] = None) -> Dict: + policy_dict, not_found_vars = get_policy_with_vars_replaced(policy_dict, var_dict or {}) if not_found_vars: return {"errors": [f"Variables not found: {', '.join(not_found_vars)}"]} diff --git a/src/tirith/core/evaluators/regex_match.py b/src/tirith/core/evaluators/regex_match.py index ec1e105a..410b70dc 100644 --- a/src/tirith/core/evaluators/regex_match.py +++ b/src/tirith/core/evaluators/regex_match.py @@ -9,7 +9,7 @@ def evaluate(self, evaluator_input, evaluator_data): evaluation_result = {"passed": False, "message": "Not evaluated"} try: match = 0 - if type(evaluator_input) in (str, list, dict) and type(evaluator_data) == str: + if type(evaluator_input) in (str, list, dict) and type(evaluator_data) is str: evaluator_input = str(evaluator_input) match = re.search(evaluator_data, evaluator_input) if match is None: