MycroftAI / lingua-franca

Mycroft's multilingual text parsing and formatting library
Apache License 2.0
75 stars 79 forks source link

fix potential circular import #215

Open ChanceNCounter opened 2 years ago

ChanceNCounter commented 2 years ago

Fixes potential circular import during the import-and-crawl phrase of localized function caching, where a localized file attempts to reference its parent. By initializing the rest of the parent file before attempting to populate the localized function dictionary, it seems to delay the whole thing (and therefore the import-and-crawl phrase) long enough to avoid the ImportError.

In reality, when the potential error hits, the parent file is still partially initialized. In other words, this could technically still be described as a circular import, but, because Python is Python, does not have the effect of one; whatever the localized file is attempting to reference in its parent, that function will necessarily already have been parsed before the localized function is imported.

This is known to work, because HelloChatterbox ran into the problem, and I've already tested the fix against their code.

ChanceNCounter commented 2 years ago

Note: this bug doesn't exist yet, but now it's impossible to write!

Additional note: Local unit tests are currently wonky because of #203, pending #209. However, there is no change in test status, either on GitHub or On My Computer. Moot point if #209 gets in before this does.