mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-12 10:16:27 +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}.")
|
E202 = ("Unsupported {name} mode '{mode}'. Supported modes: {modes}.")
|
||||||
|
|
||||||
# New errors added in v3.x
|
# 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 "
|
E854 = ("Unable to set doc.ents. Check that the 'ents_filter' does not "
|
||||||
"permit overlapping spans.")
|
"permit overlapping spans.")
|
||||||
E855 = ("Invalid {obj}: {obj} is not from the same doc.")
|
E855 = ("Invalid {obj}: {obj} is not from the same doc.")
|
||||||
|
|
|
@ -465,6 +465,8 @@ class Language:
|
||||||
"""
|
"""
|
||||||
if not isinstance(name, str):
|
if not isinstance(name, str):
|
||||||
raise ValueError(Errors.E963.format(decorator="factory"))
|
raise ValueError(Errors.E963.format(decorator="factory"))
|
||||||
|
if "." in name:
|
||||||
|
raise ValueError(Errors.E853.format(name=name))
|
||||||
if not isinstance(default_config, dict):
|
if not isinstance(default_config, dict):
|
||||||
err = Errors.E962.format(
|
err = Errors.E962.format(
|
||||||
style="default config", name=name, cfg_type=type(default_config)
|
style="default config", name=name, cfg_type=type(default_config)
|
||||||
|
@ -543,8 +545,11 @@ class Language:
|
||||||
|
|
||||||
DOCS: https://spacy.io/api/language#component
|
DOCS: https://spacy.io/api/language#component
|
||||||
"""
|
"""
|
||||||
if name is not None and not isinstance(name, str):
|
if name is not None:
|
||||||
|
if not isinstance(name, str):
|
||||||
raise ValueError(Errors.E963.format(decorator="component"))
|
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)
|
component_name = name if name is not None else util.get_object_name(func)
|
||||||
|
|
||||||
def add_component(component_func: "Pipe") -> Callable:
|
def add_component(component_func: "Pipe") -> Callable:
|
||||||
|
|
|
@ -659,3 +659,14 @@ def test_multiprocessing_gpu_warning(nlp2, texts):
|
||||||
# Trigger multi-processing.
|
# Trigger multi-processing.
|
||||||
for _ in docs:
|
for _ in docs:
|
||||||
pass
|
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