Improve E889

This commit is contained in:
Ines Montani 2021-01-29 23:39:23 +11:00
parent 924396c20c
commit 94232aea08
2 changed files with 16 additions and 5 deletions

View File

@ -483,9 +483,10 @@ class Errors:
"component that doesn't seem to support listeners. Expected Tok2Vec " "component that doesn't seem to support listeners. Expected Tok2Vec "
"or Transformer component. If you didn't call nlp.replace_listeners " "or Transformer component. If you didn't call nlp.replace_listeners "
"manually, this is likely a bug in spaCy.") "manually, this is likely a bug in spaCy.")
E889 = ("Can't replace listeners of component '{name}' because it's not " E889 = ("Can't replace '{tok2vec}' listeners of component '{name}' because "
"in the pipeline. Available components: {opts}. If you didn't call " "'{unknown}' is not in the pipeline. Available components: {opts}. "
"nlp.replace_listeners manually, this is likely a bug in spaCy.") "If you didn't call nlp.replace_listeners manually, this is likely "
"a bug in spaCy.")
E890 = ("Cannot add the alias '{alias}' to the Knowledge base. " E890 = ("Cannot add the alias '{alias}' to the Knowledge base. "
"Each alias should be a meaningful string.") "Each alias should be a meaningful string.")
E891 = ("Alias '{alias}' could not be added to the Knowledge base. " E891 = ("Alias '{alias}' could not be added to the Knowledge base. "

View File

@ -1712,10 +1712,20 @@ class Language:
DOCS: https://nightly.spacy.io/api/language#replace_listeners DOCS: https://nightly.spacy.io/api/language#replace_listeners
""" """
if tok2vec_name not in self.pipe_names: if tok2vec_name not in self.pipe_names:
err = Errors.E889.format(name=tok2vec_name, opts=", ".join(self.pipe_names)) err = Errors.E889.format(
tok2vec=tok2vec_name,
name=pipe_name,
unknown=tok2vec_name,
opts=", ".join(self.pipe_names),
)
raise ValueError(err) raise ValueError(err)
if pipe_name not in self.pipe_names: if pipe_name not in self.pipe_names:
err = Errors.E889.format(name=pipe_name, opts=", ".join(self.pipe_names)) err = Errors.E889.format(
tok2vec=tok2vec_name,
name=pipe_name,
unknown=pipe_name,
opts=", ".join(self.pipe_names),
)
raise ValueError(err) raise ValueError(err)
tok2vec = self.get_pipe(tok2vec_name) tok2vec = self.get_pipe(tok2vec_name)
tok2vec_cfg = self.get_pipe_config(tok2vec_name) tok2vec_cfg = self.get_pipe_config(tok2vec_name)