1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-16 03:18:09 +00:00

utils: fix unimporting partially-imported modules

Previously, delattr from the parent package might throw KeyError.
This commit is contained in:
Jan Pochyla 2019-01-29 13:57:24 +01:00
parent 75e65bbb2d
commit 2c2930c663

View File

@ -28,8 +28,12 @@ def unimport_end(mods):
continue
path = mod[:i]
name = mod[i + 1 :]
if path in sys.modules:
try:
delattr(sys.modules[path], name)
except KeyError:
# either path is not present in sys.modules, or module is not
# referenced from the parent package. both is fine.
pass
# collect removed modules
gc.collect()