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
pull/107357/head
J. Nick Koston 2024-01-05 23:20:30 -10:00 committed by GitHub
parent 851ad21d11
commit 6ff990e2c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 2 deletions

View File

@ -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.