mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-05 04:40:20 +03:00
move warning to get_lang_class
This commit is contained in:
parent
8b4415f29b
commit
60314f20f6
|
@ -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",
|
||||
[
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user