refactor: extract VariableDetector base class for variable detectors#235
Open
viktorbeck98 wants to merge 1 commit into
Open
refactor: extract VariableDetector base class for variable detectors#235viktorbeck98 wants to merge 1 commit into
viktorbeck98 wants to merge 1 commit into
Conversation
Factor the ~90% duplicated lifecycle (train/detect/configure/post_train/ set_configuration) shared by the five variable-value detectors into a new abstract VariableDetector base in common/variable_detector.py. Each concrete detector (new_value, charset, value_range, bigram, new_value_combo) is reduced to a config subclass plus a few override hooks; all remain in the detectors package so name-based tracker reconstruction keeps working. Also fixes latent bugs surfaced by the refactor: - ValueRangeDetector now registers persistency and preserves the persist config across set_configuration (both were previously dropped). - SingleStabilityTracker no longer starts a throwaway PersistencySaver when reconstructing a detector to recover its add_value closure (it would leak a saver thread per variable and clobber the real state file under persist). Behavior-preserving refactor guarded by the existing per-detector suites. Full suite: 545 passed. prek gate (mypy --strict, flake8, vulture, docformatter) clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Task
Description
Extracts an abstract
VariableDetectorbase class (common/variable_detector.py,inheriting
CoreDetector) that owns the shared lifecycle (train/detect/configure/post_train/set_configuration) previously duplicated ~90% across thefive variable-value detectors. Each concrete detector —
NewValue,Charset,ValueRange,BigramFrequency,NewValueCombo— is reduced to a config subclassplus a few override hooks (
_check_variable,_prepare_variables,_event_data_kwargs,_check_event,_description). All detectors stay in thedetectorspackage soname-based tracker reconstruction keeps working. Net: +439 / −712 lines.
new_event/random/ruleare untouched.Also fixes latent bugs surfaced by the refactor:
ValueRangeDetectornow registers persistency and preserves thepersistconfigacross
set_configuration(both were previously dropped).SingleStabilityTrackerno longer starts a throwawayPersistencySaverwhenreconstructing a detector to recover its
add_valueclosure (it would leak a saverthread per variable and clobber the real state file under
persist).Behavior-preserving; the only intended behavior changes are the two
value_rangefixes.How Has This Been Tested?
regression test that reconstruction under
persiststarts no throwaway saver.prekgate (mypy--strict, flake8, vulture, docformatter,bandit) clean.
Checklist