mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-17 03:48:09 +00:00
utils: fix unimporting partially-imported modules
Previously, delattr from the parent package might throw KeyError.
This commit is contained in:
parent
75e65bbb2d
commit
2c2930c663
@ -28,8 +28,12 @@ def unimport_end(mods):
|
|||||||
continue
|
continue
|
||||||
path = mod[:i]
|
path = mod[:i]
|
||||||
name = mod[i + 1 :]
|
name = mod[i + 1 :]
|
||||||
if path in sys.modules:
|
try:
|
||||||
delattr(sys.modules[path], name)
|
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
|
# collect removed modules
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user