mirror of
https://github.com/home-assistant/core.git
synced 2025-11-08 02:19:31 +00:00
Avoid expensive inspect calls in config validators (#112085)
* Avoid expensive inspect calls in config validators inspect has a performance problem https://github.com/python/cpython/issues/92041 We now avoid calling inspect unless we are going to log * remove unused * reduce * get_integration_logger
This commit is contained in:
@@ -34,6 +34,26 @@ class IntegrationFrame:
|
||||
relative_filename: str
|
||||
|
||||
|
||||
def get_integration_logger(fallback_name: str) -> logging.Logger:
|
||||
"""Return a logger by checking the current integration frame.
|
||||
|
||||
If Python is unable to access the sources files, the call stack frame
|
||||
will be missing information, so let's guard by requiring a fallback name.
|
||||
https://github.com/home-assistant/core/issues/24982
|
||||
"""
|
||||
try:
|
||||
integration_frame = get_integration_frame()
|
||||
except MissingIntegrationFrame:
|
||||
return logging.getLogger(fallback_name)
|
||||
|
||||
if integration_frame.custom_integration:
|
||||
logger_name = f"custom_components.{integration_frame.integration}"
|
||||
else:
|
||||
logger_name = f"homeassistant.components.{integration_frame.integration}"
|
||||
|
||||
return logging.getLogger(logger_name)
|
||||
|
||||
|
||||
def get_integration_frame(exclude_integrations: set | None = None) -> IntegrationFrame:
|
||||
"""Return the frame, integration and integration path of the current stack frame."""
|
||||
found_frame = None
|
||||
|
||||
Reference in New Issue
Block a user