Skip to content

MAINT: Formalize JSON-condition helper contract on MemoryInterface#1814

Merged
romanlutz merged 3 commits into
microsoft:mainfrom
romanlutz:romanlutz/formalize-memory-json-condition-contract
May 26, 2026
Merged

MAINT: Formalize JSON-condition helper contract on MemoryInterface#1814
romanlutz merged 3 commits into
microsoft:mainfrom
romanlutz:romanlutz/formalize-memory-json-condition-contract

Conversation

@romanlutz
Copy link
Copy Markdown
Contributor

@romanlutz romanlutz commented May 26, 2026

What

Tightens the polymorphic contract for _get_condition_json_property_match and _get_condition_json_array_match on MemoryInterface. The abstract decls already existed; this PR adds an explicit "Concrete subclasses translate this contract into their SQL dialect…" sentence to both abstract docstrings so the dialect-divergence reason for the polymorphism is captured in one place.

Why @abstractmethod and not "extract to a shared function"

The two implementations have identical signatures but completely different SQL — SQLite uses json_extract / json_each, Azure SQL uses JSON_VALUE / ISJSON / OPENJSON / JSON_QUERY. There is no shared logic to extract; every line is dialect-specific. The right way to formalize the polymorphism is an abstract method on the base, not a shared function or mixin. Callers in memory_interface.py (e.g. get_attack_results, _get_condition_json_match) already dispatch through self._get_condition_json_* — this PR just makes the contract those callers depend on explicit and well-documented in one place.

Subclass docstrings are intentionally kept full (not collapsed to "see base class") because the doc builder and IDE hover don't auto-inherit docstrings — whatever is in the file is what renders.

Verified

  • uv run pytest tests/unit -x -q — 8049 passed, 118 skipped
  • uv run pre-commit run --all-files — clean (ruff, ty, etc.)

Copilot AI added 2 commits May 26, 2026 14:29
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread pyrit/memory/memory_interface.py Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@romanlutz romanlutz added this pull request to the merge queue May 26, 2026
Merged via the queue into microsoft:main with commit 2c7c3e4 May 26, 2026
48 of 49 checks passed
@romanlutz romanlutz deleted the romanlutz/formalize-memory-json-condition-contract branch May 26, 2026 23:41
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.

3 participants