From d1df6e6fbabdd1137016c28160a8a129a4caa1c8 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Fri, 9 Apr 2021 07:26:09 +0200 Subject: [PATCH] Don't get code_context when calling inspect.stack (#48849) * Don't get code_context when calling inspect.stack * Update homeassistant/helpers/config_validation.py --- homeassistant/helpers/config_validation.py | 2 +- homeassistant/helpers/deprecation.py | 2 +- homeassistant/util/logging.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 9b56bb06865..21d04f11551 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -711,7 +711,7 @@ def deprecated( - No warning if neither key nor replacement_key are provided - Adds replacement_key with default value in this case """ - module = inspect.getmodule(inspect.stack()[1][0]) + module = inspect.getmodule(inspect.stack(context=0)[1].frame) if module is not None: module_name = module.__name__ else: diff --git a/homeassistant/helpers/deprecation.py b/homeassistant/helpers/deprecation.py index 38b1dfca437..06f09327dc9 100644 --- a/homeassistant/helpers/deprecation.py +++ b/homeassistant/helpers/deprecation.py @@ -59,7 +59,7 @@ def get_deprecated( and a warning is issued to the user. """ if old_name in config: - module = inspect.getmodule(inspect.stack()[1][0]) + module = inspect.getmodule(inspect.stack(context=0)[1].frame) if module is not None: module_name = module.__name__ else: diff --git a/homeassistant/util/logging.py b/homeassistant/util/logging.py index ba846c0e8b4..816af95718d 100644 --- a/homeassistant/util/logging.py +++ b/homeassistant/util/logging.py @@ -85,7 +85,7 @@ def async_activate_log_queue_handler(hass: HomeAssistant) -> None: def log_exception(format_err: Callable[..., Any], *args: Any) -> None: """Log an exception with additional context.""" - module = inspect.getmodule(inspect.stack()[1][0]) + module = inspect.getmodule(inspect.stack(context=0)[1].frame) if module is not None: module_name = module.__name__ else: