Also raise original error message in util.get_lang_class

Otherwise, the true error that happens within a Language subclass is swallowed, because if it's imported lazily like that, it'll always be an ImportError
This commit is contained in:
Ines Montani 2019-02-13 16:52:25 +01:00
parent 4d2438f985
commit 60c2a3bb65
2 changed files with 3 additions and 3 deletions

View File

@ -177,7 +177,7 @@ class Errors(object):
"you forget to call the `set_extension` method?") "you forget to call the `set_extension` method?")
E047 = ("Can't assign a value to unregistered extension attribute " E047 = ("Can't assign a value to unregistered extension attribute "
"'{name}'. Did you forget to call the `set_extension` method?") "'{name}'. Did you forget to call the `set_extension` method?")
E048 = ("Can't import language {lang} from spacy.lang.") E048 = ("Can't import language {lang} from spacy.lang: {err}")
E049 = ("Can't find spaCy data directory: '{path}'. Check your " E049 = ("Can't find spaCy data directory: '{path}'. Check your "
"installation and permissions, or use spacy.util.set_data_path " "installation and permissions, or use spacy.util.set_data_path "
"to customise the location if necessary.") "to customise the location if necessary.")

View File

@ -53,8 +53,8 @@ def get_lang_class(lang):
if lang not in LANGUAGES: if lang not in LANGUAGES:
try: try:
module = importlib.import_module(".lang.%s" % lang, "spacy") module = importlib.import_module(".lang.%s" % lang, "spacy")
except ImportError: except ImportError as err:
raise ImportError(Errors.E048.format(lang=lang)) raise ImportError(Errors.E048.format(lang=lang, err=err))
LANGUAGES[lang] = getattr(module, module.__all__[0]) LANGUAGES[lang] = getattr(module, module.__all__[0])
return LANGUAGES[lang] return LANGUAGES[lang]