#597·TextBlob

filter_insignificant exhausts generator-based tag suffixes before later tokens

Author: Afloat16Created Sep 29, 2026Updated Sep 29, 2026

Problem and proposed change

tag_suffixes is annotated as Iterable[str], but it is iterated repeatedly for each token. A generator is exhausted after earlier tokens, so later insignificant words leak into the result. Materialize the suffix iterable once before the token loop.

Reproduction

python
from textblob.utils import filter_insignificant
chunk = [("the", "DT"), ("cat", "NN"), ("and", "CC"), ("dog", "NN")]
print(filter_insignificant(chunk, (x for x in ["DT", "CC"])))
# Expected: [("cat", "NN"), ("dog", "NN")]; actual also contains ("and", "CC").

Validation

Source: src/textblob/utils.py, Git blob 43883f230479c1ec41e8e9a54e231b6b6c9f5ed7; rechecked against current upstream. Focused before/after tests were rerun for this submission.

Complete standalone source module loaded with real dependencies; selected utility behaviors tested. Not the full project suite.

Before: 3 failed, 4 passed in 0.03s

After: 7 passed in 0.01s

Candidate patch

diff
--- a/src/textblob/utils.py
+++ b/src/textblob/utils.py
@@ -46,6 +46,7 @@
     chunk, tag_suffixes: Iterable[str] = ("DT", "CC", "PRP$", "PRP")
 ):
     """Filter out insignificant (word, tag) tuples from a chunk of text."""
+    tag_suffixes = tuple(tag_suffixes)
     good: list[tuple[str, str]] = []
     for word, tag in chunk:
         ok = True