Skip to content

Commit 8316bc7

Browse files
committed
bugfix DisabledPipes
1 parent 18dfb27 commit 8316bc7

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

spacy/language.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,9 @@ def select_pipes(
10341034
)
10351035
)
10361036
disable = to_disable
1037+
# DisabledPipes will restore the pipes in 'disable' when it's done, so we need to exclude
1038+
# those pipes that were already disabled.
1039+
disable = [d for d in disable if d not in self._disabled]
10371040
return DisabledPipes(self, disable)
10381041

10391042
def make_doc(self, text: str) -> Doc:

spacy/tests/pipeline/test_pipe_methods.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,27 @@ def test_enable_pipes_method(nlp, name):
129129

130130
@pytest.mark.parametrize("name", ["my_component"])
131131
def test_disable_pipes_context(nlp, name):
132+
"""Test that an enabled component stays enabled after running the context manager."""
132133
nlp.add_pipe("new_pipe", name=name)
133134
assert nlp.has_pipe(name)
134135
with nlp.select_pipes(disable=name):
135136
assert not nlp.has_pipe(name)
136137
assert nlp.has_pipe(name)
137138

138139

140+
@pytest.mark.parametrize("name", ["my_component"])
141+
def test_disable_pipes_context_restore(nlp, name):
142+
"""Test that a disabled component stays disabled after running the context manager."""
143+
nlp.add_pipe("new_pipe", name=name)
144+
assert nlp.has_pipe(name)
145+
nlp.disable_pipes(name)
146+
assert not nlp.has_pipe(name)
147+
with nlp.select_pipes(disable=name):
148+
assert not nlp.has_pipe(name)
149+
assert not nlp.has_pipe(name)
150+
151+
152+
139153
def test_select_pipes_list_arg(nlp):
140154
for name in ["c1", "c2", "c3"]:
141155
nlp.add_pipe("new_pipe", name=name)

0 commit comments

Comments
 (0)