fix(refusal_classifier): quote self-referential annotation to fix import NameError - #345
Merged
msoedov merged 1 commit intoSep 11, 2026
Conversation
…fix import NameError
Owner
|
@Anai-Guo thx for the patch! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
agentic_security/refusal_classifier/hybrid_classifier.pyraisesNameErrorat import time, which breaks the entireHybridRefusalClassifiermodule (and any test or code that imports it).The
add_detectormethod is defined insideclass HybridRefusalClassifierwith a return annotation that refers to the class itself:The module does not use
from __future__ import annotations, so this return annotation is evaluated eagerly while the class body is still executing — at which point the nameHybridRefusalClassifieris not yet bound. Importing the module fails:Because
tests/unit/refusal_classifier/test_hybrid_classifier.pyimports the module at the top level, that whole test file currently fails to collect.The module-level factory
create_hybrid_classifier(...) -> HybridRefusalClassifieris fine — it runs after the class is defined; only the in-class self-reference is affected.Fix
Quote the self-referential annotation so it becomes a forward reference (standard PEP 484 pattern), matching how self-references are normally written without
from __future__ import annotations:One-line change, no behavior change.
Verification
Before:
import agentic_security.refusal_classifier.hybrid_classifier→NameError.After: the module imports cleanly and
HybridRefusalClassifier()instantiates, sotests/unit/refusal_classifier/test_hybrid_classifier.pycan be collected again.🤖 Generated with Claude Code