move warning to get_lang_class

This commit is contained in:
thomashacker 2022-11-14 11:27:41 +01:00
parent 8b4415f29b
commit 60314f20f6
2 changed files with 5 additions and 8 deletions

View File

@ -543,6 +543,7 @@ def test_spacy_blank():
assert nlp.config["training"]["dropout"] == 0.2
assert nlp.meta["name"] == "my_custom_model"
@pytest.mark.parametrize(
"lang,target",
[
@ -566,12 +567,9 @@ def test_language_matching(lang, target):
Test that we can look up languages by equivalent or nearly-equivalent
language codes.
"""
if target is None:
assert find_matching_language(lang) == target
else:
with pytest.warns(UserWarning):
assert find_matching_language(lang) == target
@pytest.mark.parametrize(
"lang,target",
[

View File

@ -283,7 +283,6 @@ def find_matching_language(lang: str) -> Optional[str]:
import spacy.lang # noqa: F401
if lang == "xx":
warnings.warn(Warnings.W124.format(lang=lang, renamed_lang="mul"))
return "mul"
# Find out which language modules we have
@ -302,8 +301,6 @@ def find_matching_language(lang: str) -> Optional[str]:
# is labeled that way is probably trying to be distinct from 'zh' and
# shouldn't automatically match.
match = langcodes.closest_supported_match(lang, possible_languages, max_distance=9)
if match is not None:
warnings.warn(Warnings.W124.format(lang=lang, renamed_lang=match))
return match
@ -330,6 +327,8 @@ def get_lang_class(lang: str) -> Type["Language"]:
match = None
if match:
if match != lang:
warnings.warn(Warnings.W124.format(lang=lang, renamed_lang=match))
lang = match
module = importlib.import_module(f".lang.{lang}", "spacy")
else: