diff --git a/spacy/errors.py b/spacy/errors.py index b01afcb80..bff8e7414 100644 --- a/spacy/errors.py +++ b/spacy/errors.py @@ -199,6 +199,7 @@ class Warnings(metaclass=ErrorsWithCodes): W118 = ("Term '{term}' not found in glossary. It may however be explained in documentation " "for the corpora used to train the language. Please check " "`nlp.meta[\"sources\"]` for any relevant links.") + W119 = ("Overriding pipe name in `config` is not supported. Ignoring override '{name_in_config}'.") class Errors(metaclass=ErrorsWithCodes): diff --git a/spacy/language.py b/spacy/language.py index bab403f0e..faca1f258 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -774,6 +774,9 @@ class Language: name = name if name is not None else factory_name if name in self.component_names: raise ValueError(Errors.E007.format(name=name, opts=self.component_names)) + # Overriding pipe name in the config is not supported and will be ignored. + if "name" in config: + warnings.warn(Warnings.W119.format(name_in_config=config.pop("name"))) if source is not None: # We're loading the component from a model. After loading the # component, we know its real factory name diff --git a/spacy/tests/pipeline/test_pipe_factories.py b/spacy/tests/pipeline/test_pipe_factories.py index 4128e2a48..4340a4b88 100644 --- a/spacy/tests/pipeline/test_pipe_factories.py +++ b/spacy/tests/pipeline/test_pipe_factories.py @@ -119,6 +119,7 @@ def test_pipe_class_component_config(): self.value1 = value1 self.value2 = value2 self.is_base = True + self.name = name def __call__(self, doc: Doc) -> Doc: return doc @@ -141,12 +142,14 @@ def test_pipe_class_component_config(): nlp.add_pipe(name) with pytest.raises(ConfigValidationError): # invalid config nlp.add_pipe(name, config={"value1": "10", "value2": "hello"}) - nlp.add_pipe(name, config={"value1": 10, "value2": "hello"}) + with pytest.warns(UserWarning): + nlp.add_pipe(name, config={"value1": 10, "value2": "hello", "name": "wrong_name"}) pipe = nlp.get_pipe(name) assert isinstance(pipe.nlp, Language) assert pipe.value1 == 10 assert pipe.value2 == "hello" assert pipe.is_base is True + assert pipe.name == name nlp_en = English() with pytest.raises(ConfigValidationError): # invalid config