mirror of
https://github.com/explosion/spaCy.git
synced 2025-05-03 23:33:40 +03:00
Remove extra pipe config values before merging
This commit is contained in:
parent
d3d7f92f05
commit
91a6637f74
|
@ -396,8 +396,6 @@ class Language:
|
||||||
if name not in self._pipe_configs:
|
if name not in self._pipe_configs:
|
||||||
raise ValueError(Errors.E960.format(name=name))
|
raise ValueError(Errors.E960.format(name=name))
|
||||||
pipe_config = self._pipe_configs[name]
|
pipe_config = self._pipe_configs[name]
|
||||||
pipe_config.pop("nlp", None)
|
|
||||||
pipe_config.pop("name", None)
|
|
||||||
return pipe_config
|
return pipe_config
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -650,6 +648,10 @@ class Language:
|
||||||
filled = Config(filled[factory_name])
|
filled = Config(filled[factory_name])
|
||||||
filled["factory"] = factory_name
|
filled["factory"] = factory_name
|
||||||
filled.pop("@factories", None)
|
filled.pop("@factories", None)
|
||||||
|
# Remove the extra values we added because we don't want to keep passing
|
||||||
|
# them around, copying them etc.
|
||||||
|
filled.pop("nlp", None)
|
||||||
|
filled.pop("name", None)
|
||||||
# Merge the final filled config with the raw config (including non-
|
# Merge the final filled config with the raw config (including non-
|
||||||
# interpolated variables)
|
# interpolated variables)
|
||||||
if raw_config:
|
if raw_config:
|
||||||
|
|
|
@ -470,3 +470,21 @@ def test_pipe_factories_decorator_idempotent():
|
||||||
nlp = Language()
|
nlp = Language()
|
||||||
nlp.add_pipe(name)
|
nlp.add_pipe(name)
|
||||||
Language.component(name2, func=func2)
|
Language.component(name2, func=func2)
|
||||||
|
|
||||||
|
|
||||||
|
def test_pipe_factories_config_excludes_nlp():
|
||||||
|
"""Test that the extra values we temporarily add to component config
|
||||||
|
blocks/functions are removed and not copied around.
|
||||||
|
"""
|
||||||
|
name = "test_pipe_factories_config_excludes_nlp"
|
||||||
|
func = lambda nlp, name: lambda doc: doc
|
||||||
|
Language.factory(name, func=func)
|
||||||
|
config = {
|
||||||
|
"nlp": {"lang": "en", "pipeline": [name]},
|
||||||
|
"components": {name: {"factory": name}},
|
||||||
|
}
|
||||||
|
nlp = English.from_config(config)
|
||||||
|
assert nlp.pipe_names == [name]
|
||||||
|
pipe_cfg = nlp.get_pipe_config(name)
|
||||||
|
pipe_cfg == {"factory": name}
|
||||||
|
assert nlp._pipe_configs[name] == {"factory": name}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user