Python 3: Filter out None values returned by getmodule(...) to fix the stack inspection

Signed-off-by: Fadi Moukayed <smfadi@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Fadi Moukayed 2015-08-06 14:07:25 +02:00 committed by FUJITA Tomonori
parent 3b4a82bab2
commit 45c14ec59b

View File

@ -77,11 +77,12 @@ def require_app(app_name, api_style=False):
If this is used for client application module, set api_style=False.
"""
iterable = (inspect.getmodule(frame[0]) for frame in inspect.stack())
modules = [module for module in iterable if module is not None]
if api_style:
frm = inspect.stack()[2] # skip a frame for "api" module
m = modules[2] # skip a frame for "api" module
else:
frm = inspect.stack()[1]
m = inspect.getmodule(frm[0]) # client module
m = modules[1]
m._REQUIRED_APP = getattr(m, '_REQUIRED_APP', [])
m._REQUIRED_APP.append(app_name)
LOG.debug('require_app: %s is required by %s', app_name, m.__name__)