Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion specforge/data/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def register(self, name: str, template: ChatTemplate, override: bool = False):
override(bool): Whether to override the existing template, default to False
"""
assert (
not override and name not in self.templates
override or name not in self.templates
), f"Chat template for the model type {name} has already been registered"
Comment on lines 61 to 63
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using assert for runtime validation is generally discouraged in Python because assertions can be globally disabled (e.g., via the -O flag), which would bypass this safety check. Since this registry logic is important for preventing accidental template overwrites, using an explicit if statement with a ValueError is more robust and follows standard Python practices for argument validation.

        if not override and name in self.templates:
            raise ValueError(f"Chat template for the model type {name} has already been registered")

self.templates[name] = template
Comment on lines 61 to 64
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change fixes override=True, but there’s no unit test asserting that register(..., override=True) can overwrite an existing key (and that override=False rejects duplicates). Adding a small test would prevent regressions in this control-flow.

Copilot uses AI. Check for mistakes.

Expand Down
Loading