From 6ff990e2c2f6a9f49af17a477318789ec8dd883a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 5 Jan 2024 23:20:30 -1000 Subject: [PATCH] Avoid fetching logger in check_if_deprecated_constant if there is nothing to log (#107341) getLogger needs a threading lock so its nice to avoid calling it if we are not going to log anything --- homeassistant/helpers/deprecation.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/helpers/deprecation.py b/homeassistant/helpers/deprecation.py index 18a42ce9bcf..cf76bc78aa5 100644 --- a/homeassistant/helpers/deprecation.py +++ b/homeassistant/helpers/deprecation.py @@ -252,7 +252,6 @@ def check_if_deprecated_constant(name: str, module_globals: dict[str, Any]) -> A Otherwise raise AttributeError. """ module_name = module_globals.get("__name__") - logger = logging.getLogger(module_name) value = replacement = None if (deprecated_const := module_globals.get(_PREFIX_DEPRECATED + name)) is None: raise AttributeError(f"Module {module_name!r} has no attribute {name!r}") @@ -273,7 +272,7 @@ def check_if_deprecated_constant(name: str, module_globals: dict[str, Any]) -> A "but an instance of DeprecatedConstant or DeprecatedConstantEnum is required" ) - logger.debug(msg) + logging.getLogger(module_name).debug(msg) # PEP 562 -- Module __getattr__ and __dir__ # specifies that __getattr__ should raise AttributeError if the attribute is not # found.