Skip to content

fix: avoid mutable default arguments and use identity check for type comparison - #282

Open
harshadkhetpal wants to merge 1 commit into
StackGuardian:mainfrom
harshadkhetpal:fix/mutable-defaults-and-type-identity
Open

fix: avoid mutable default arguments and use identity check for type comparison#282
harshadkhetpal wants to merge 1 commit into
StackGuardian:mainfrom
harshadkhetpal:fix/mutable-defaults-and-type-identity

Conversation

@harshadkhetpal

Copy link
Copy Markdown

Summary

Three small correctness fixes flagged by ruff (B006 / E721):

  1. src/tirith/core/core.pystart_policy_evaluation(var_paths: List[str] = [], inline_vars: List[str] = []) and start_policy_evaluation_from_dict(var_dict: Dict = {}) used mutable default arguments. Python evaluates defaults once at definition time, so the same list/dict object is shared across every call — a latent state-leak footgun, especially for var_dict, which is passed into get_policy_with_vars_replaced(). Changed to the Optional[...] = None sentinel pattern with normalization at the top of each function; behavior is unchanged for all existing callers.

  2. src/tirith/core/evaluators/regex_match.pytype(evaluator_data) == str compares type objects with ==; identity (is str) is the intended semantics and is what newer linters (ruff E721) require.

Testing

python -m py_compile passes on both files and ruff check --select B006,E721 is clean after the change. No functional change for existing callers.

🤖 Generated with Claude Code

…comparison

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants