Skip to content

Commit

Permalink
chore: replace f-strings in loggers (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Mar 1, 2024
1 parent 4a6b8b0 commit 771a369
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions a_sync/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)


Expand All @@ -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:
Expand Down

0 comments on commit 771a369

Please sign in to comment.