Skip to content

MAINT: Consolidate regex scorer defaults - #2351

Open
Roman Lutz (romanlutz) wants to merge 1 commit into
microsoft:mainfrom
romanlutz:romanlutz-regex-scorer-defaults
Open

MAINT: Consolidate regex scorer defaults#2351
Roman Lutz (romanlutz) wants to merge 1 commit into
microsoft:mainfrom
romanlutz:romanlutz-regex-scorer-defaults

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Description

The public regex scorer subclasses repeat the same pass-through constructor logic for selecting default patterns, categories, and score aggregation. This change centralizes that behavior in RegexScorer through private constructor mixins and declarative class defaults.

The refactor preserves the existing public API and behavior: configurable scorers retain patterns and score_aggregator, fixed keyword scorers retain zero-argument construction, and StaticPromptInjectionScorer keeps its distinct categories override. Pattern order, per-instance copies, custom replacements, exported names, identifiers, and subclass semantics remain unchanged. Fifteen duplicated constructor bodies are removed, reducing production code by a net 243 lines.

Tests and Documentation

Added focused regression coverage for public constructor signatures, default pattern content and order, copy semantics, categories, custom pattern and aggregator overrides, exports, subclass identity, and identifier JSON round-tripping.

Ruff format/check, targeted ty, compile checks, git diff --check, and isolated runtime contract checks across all 15 affected subclasses passed. The comprehensive regex pytest suite could not start in this worktree because its empty .venv could not be restored: uv sync --offline first lacked cached ty==0.0.65, while online synchronization repeatedly failed TLS handshakes against files.pythonhosted.org. Documentation was not changed because this is behavior-preserving.

Move shared configurable and fixed constructor behavior into declarative regex scorer defaults while preserving public signatures and overrides.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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