mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
Adjust error message and add test
This commit is contained in:
parent
2110e8f86d
commit
d3b3663942
|
@ -85,8 +85,11 @@ class Warnings:
|
|||
"attribute or operator.")
|
||||
|
||||
# TODO: fix numbering after merging develop into master
|
||||
W088 = ("This component implements a 'begin_training' method, "
|
||||
"which should probably be renamed to 'initialize'.")
|
||||
W088 = ("The pipeline component {name} implements a 'begin_training' "
|
||||
"method, which won't be called by spaCy. As of v3.0, 'begin_training' "
|
||||
"has been renamed to 'initialize' so you likely want to rename the "
|
||||
"component method. See the documentation for details: "
|
||||
"https://nightly.spacy.io/api/language#initialize")
|
||||
W089 = ("The nlp.begin_training method has been renamed to nlp.initialize.")
|
||||
W090 = ("Could not locate any {format} files in path '{path}'.")
|
||||
W091 = ("Could not clean/remove the temp directory at {dir}: {msg}.")
|
||||
|
|
|
@ -39,7 +39,7 @@ cdef class Pipe:
|
|||
"""Raise a warning if an inheriting class implements 'begin_training'
|
||||
(from v2) instead of the new 'initialize' method (from v3)"""
|
||||
if hasattr(cls, "begin_training"):
|
||||
warnings.warn(Warnings.W088)
|
||||
warnings.warn(Warnings.W088.format(name=cls.__name__))
|
||||
|
||||
@property
|
||||
def labels(self) -> Optional[Tuple[str]]:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import pytest
|
||||
from spacy.language import Language
|
||||
from spacy.pipeline import Pipe
|
||||
from spacy.util import SimpleFrozenList, get_arg_names
|
||||
|
||||
|
||||
|
@ -370,3 +371,14 @@ def test_pipe_label_data_no_labels(pipe):
|
|||
initialize = getattr(pipe, "initialize", None)
|
||||
if initialize is not None:
|
||||
assert "labels" not in get_arg_names(initialize)
|
||||
|
||||
|
||||
def test_warning_pipe_begin_training():
|
||||
with pytest.warns(UserWarning, match="begin_training"):
|
||||
|
||||
class IncompatPipe(Pipe):
|
||||
def __init__(self):
|
||||
...
|
||||
|
||||
def begin_training(*args, **kwargs):
|
||||
...
|
||||
|
|
Loading…
Reference in New Issue
Block a user