From 771a3696419f286e5a2302fd98f1a2379c2ca650 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Thu, 29 Feb 2024 21:09:54 -0500 Subject: [PATCH] chore: replace f-strings in loggers (#149) --- a_sync/_meta.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/a_sync/_meta.py b/a_sync/_meta.py index 85db68ed..33a0c5b2 100644 --- a/a_sync/_meta.py +++ b/a_sync/_meta.py @@ -17,43 +17,43 @@ class ASyncMeta(ABCMeta): """Any class with metaclass ASyncMeta will have its functions wrapped with a_sync upon class instantiation.""" def __new__(cls, new_class_name, bases, attrs): _update_logger(new_class_name) - logger.debug(f"woah, you're defining a new ASync class `%s`! let's walk thru it together", new_class_name) - logger.debug(f"first, I check whether you've defined any modifiers on `%s`", new_class_name) - # NOTE: Open uesion: what do we do when a parent class and subclass define the same modifier differently? + logger.debug("woah, you're defining a new ASync class `%s`! let's walk thru it together", new_class_name) + logger.debug("first, I check whether you've defined any modifiers on `%s`", new_class_name) + # NOTE: Open quesion: what do we do when a parent class and subclass define the same modifier differently? # Currently the parent value is used for functions defined on the parent, # and the subclass value is used for functions defined on the subclass. class_defined_modifiers = modifiers.get_modifiers_from(attrs) - logger.debug(f'found modifiers: %s', class_defined_modifiers) + logger.debug('found modifiers: %s', class_defined_modifiers) logger.debug("now I inspect the class definition to figure out which attributes need to be wrapped") for attr_name, attr_value in list(attrs.items()): if attr_name.startswith("_"): - logger.debug(f"`%s.%s` starts with an underscore, skipping", new_class_name, attr_name) + logger.debug("`%s.%s` starts with an underscore, skipping", new_class_name, attr_name) continue elif "__" in attr_name: - logger.debug(f"`%s.%s` incluldes a double-underscore, skipping", new_class_name, attr_name) + logger.debug("`%s.%s` incluldes a double-underscore, skipping", new_class_name, attr_name) continue elif isinstance(attr_value, (_ASyncFutureWrappedFn, Semaphore)): - logger.debug(f"`%s.%s` is a %s, skipping", new_class_name, attr_name, attr_value.__class__.__name__) + logger.debug("`%s.%s` is a %s, skipping", new_class_name, attr_name, attr_value.__class__.__name__) continue logger.debug(f"inspecting `{new_class_name}.{attr_name}` of type {attr_value.__class__.__name__}") fn_modifiers = dict(class_defined_modifiers) # Special handling for functions decorated with a_sync decorators if isinstance(attr_value, ModifiedMixin): - logger.debug(f"`{new_class_name}.{attr_name}` is a `ModifiedMixin` object, which means you decorated it with the a_sync decorator even though `{new_class_name}` is an ASync class") - logger.debug(f"you probably did this so you could apply some modifiers to `{attr_name}` specifically") + logger.debug("`%s.%s` is a `ModifiedMixin` object, which means you decorated it with an a_sync decorator even though `%s` is an ASyncABC class", new_class_name, attr_name, new_class_name) + logger.debug("you probably did this so you could apply some modifiers to `%s` specifically", attr_name) modified_modifiers = attr_value.modifiers._modifiers if modified_modifiers: - logger.debug(f"I found `{new_class_name}.{attr_name}` is modified with {modified_modifiers}") + logger.debug("I found `%s.%s` is modified with %s", new_class_name, attr_name, modified_modifiers) fn_modifiers.update(modified_modifiers) else: - logger.debug(f"I did not find any modifiers") - logger.debug(f"full modifier set for `{new_class_name}.{attr_name}`: {fn_modifiers}") + logger.debug("I did not find any modifiers") + logger.debug("full modifier set for `%s.%s`: %s", new_class_name, attr_name, fn_modifiers) if isinstance(attr_value, (ASyncPropertyDescriptor, ASyncCachedPropertyDescriptor)): # Wrap property - logger.debug(f"`{attr_name} is a property, now let's wrap it") - logger.debug(f"since `{attr_name}` is a property, we will add a hidden dundermethod so you can still access it both sync and async") + logger.debug("`%s is a property, now let's wrap it", attr_name) + logger.debug("since `%s` is a property, we will add a hidden dundermethod so you can still access it both sync and async", attr_name) attrs[attr_value.hidden_method_name] = attr_value.hidden_method_descriptor - logger.debug(f"`{new_class_name}.{attr_value.hidden_method_name}` is now {attr_value.hidden_method_descriptor}") + logger.debug("`%s.%s` is now %s", new_class_name, attr_value.hidden_method_name, attr_value.hidden_method_descriptor) elif isinstance(attr_value, ASyncFunction): attrs[attr_name] = ASyncMethodDescriptor(attr_value, **fn_modifiers) else: @@ -63,7 +63,7 @@ def __new__(cls, new_class_name, bases, attrs): # NOTE We will need to improve this logic if somebody needs to use it with classmethods or staticmethods. attrs[attr_name] = ASyncMethodDescriptor(attr_value, **fn_modifiers) else: - logger.debug(f"`{new_class_name}.{attr_name}` is not callable, we will take no action with it") + logger.debug("`%s.%s` is not callable, we will take no action with it", new_class_name, attr_name) return super(ASyncMeta, cls).__new__(cls, new_class_name, bases, attrs) @@ -72,7 +72,6 @@ def __init__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) cls.__instances: Dict[bool, object] = {} cls.__lock = threading.Lock() super().__init__(name, bases, namespace) - def __call__(cls, *args: Any, **kwargs: Any): is_sync = cls.__a_sync_instance_will_be_sync__(args, kwargs) # type: ignore [attr-defined] if is_sync not in cls.__instances: