mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 17:06:29 +03:00
Check for . in factory names (#11336)
This commit is contained in:
parent
09b3118b26
commit
3e4cf1bbe1
|
@ -540,6 +540,8 @@ class Errors(metaclass=ErrorsWithCodes):
|
|||
E202 = ("Unsupported {name} mode '{mode}'. Supported modes: {modes}.")
|
||||
|
||||
# New errors added in v3.x
|
||||
E853 = ("Unsupported component factory name '{name}'. The character '.' is "
|
||||
"not permitted in factory names.")
|
||||
E854 = ("Unable to set doc.ents. Check that the 'ents_filter' does not "
|
||||
"permit overlapping spans.")
|
||||
E855 = ("Invalid {obj}: {obj} is not from the same doc.")
|
||||
|
|
|
@ -465,6 +465,8 @@ class Language:
|
|||
"""
|
||||
if not isinstance(name, str):
|
||||
raise ValueError(Errors.E963.format(decorator="factory"))
|
||||
if "." in name:
|
||||
raise ValueError(Errors.E853.format(name=name))
|
||||
if not isinstance(default_config, dict):
|
||||
err = Errors.E962.format(
|
||||
style="default config", name=name, cfg_type=type(default_config)
|
||||
|
@ -543,8 +545,11 @@ class Language:
|
|||
|
||||
DOCS: https://spacy.io/api/language#component
|
||||
"""
|
||||
if name is not None and not isinstance(name, str):
|
||||
raise ValueError(Errors.E963.format(decorator="component"))
|
||||
if name is not None:
|
||||
if not isinstance(name, str):
|
||||
raise ValueError(Errors.E963.format(decorator="component"))
|
||||
if "." in name:
|
||||
raise ValueError(Errors.E853.format(name=name))
|
||||
component_name = name if name is not None else util.get_object_name(func)
|
||||
|
||||
def add_component(component_func: "Pipe") -> Callable:
|
||||
|
|
|
@ -659,3 +659,14 @@ def test_multiprocessing_gpu_warning(nlp2, texts):
|
|||
# Trigger multi-processing.
|
||||
for _ in docs:
|
||||
pass
|
||||
|
||||
|
||||
def test_dot_in_factory_names(nlp):
|
||||
Language.component("my_evil_component", func=evil_component)
|
||||
nlp.add_pipe("my_evil_component")
|
||||
|
||||
with pytest.raises(ValueError, match="not permitted"):
|
||||
Language.component("my.evil.component.v1", func=evil_component)
|
||||
|
||||
with pytest.raises(ValueError, match="not permitted"):
|
||||
Language.factory("my.evil.component.v1", func=evil_component)
|
||||
|
|
Loading…
Reference in New Issue
Block a user