From b5e378c4942e07a71d3e7851a04e042e37e61c3f Mon Sep 17 00:00:00 2001 From: Taksh Date: Wed, 1 Jul 2026 06:15:41 +0530 Subject: [PATCH] fix: stop HyponymDetector mutating the global BASE_PATTERNS `self.patterns = BASE_PATTERNS` aliased the module-level list, so `self.patterns.extend(EXTENDED_PATTERNS)` mutated it in place. Each extended detector permanently appended EXTENDED_PATTERNS to the global list (duplicating on every later instance), leaking extended patterns into subsequent non-extended detectors. Copy the list before extending. Co-authored-by: Cursor --- scispacy/hyponym_detector.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scispacy/hyponym_detector.py b/scispacy/hyponym_detector.py index d0fc27d2..672e76e5 100644 --- a/scispacy/hyponym_detector.py +++ b/scispacy/hyponym_detector.py @@ -38,7 +38,10 @@ def __init__( ): self.nlp = nlp - self.patterns = BASE_PATTERNS + # Copy: `= BASE_PATTERNS` then `.extend(...)` mutated the module-global + # list, so each extended detector permanently appended EXTENDED_PATTERNS + # (and duplicated them) for every later detector. + self.patterns = list(BASE_PATTERNS) if extended: self.patterns.extend(EXTENDED_PATTERNS)