Replace assertion with exception

This commit is contained in:
shadeMe 2023-07-05 12:47:17 +02:00
parent 47234f58ed
commit a8ceeb5ccd
No known key found for this signature in database
GPG Key ID: 6FCA9FC635B2A402
2 changed files with 6 additions and 5 deletions

View File

@ -981,6 +981,8 @@ class Errors(metaclass=ErrorsWithCodes):
" 'min_length': {min_length}, 'max_length': {max_length}")
E1054 = ("The text, including whitespace, must match between reference and "
"predicted docs when training {component}.")
E1055 = ("The 'replace_listener' callback expects {num_params} parameters, "
"but only callbacks with one or three parameters are supported")
# Deprecated model shortcuts, only used in errors and warnings

View File

@ -2041,14 +2041,13 @@ class Language:
num_params = len(
inspect.signature(replace_listener_func).parameters
)
assert num_params in (
1,
3,
), f"'replace_listener' callback expects {num_params} parameters, but we only support one or three"
if num_params == 1:
new_model = replace_listener_func(new_model)
else:
elif num_params == 3:
new_model = replace_listener_func(new_model, listener, tok2vec)
else:
raise ValueError(Errors.E1055.format(num_params=num_params))
util.replace_model_node(pipe.model, listener, new_model) # type: ignore[attr-defined]
tok2vec.remove_listener(listener, pipe_name)