diff --git a/src/object_filtering/object_filtering.py b/src/object_filtering/object_filtering.py index d3b0441..c3d6373 100644 --- a/src/object_filtering/object_filtering.py +++ b/src/object_filtering/object_filtering.py @@ -216,10 +216,9 @@ def is_rule_valid(rule: dict, obj: Any = None) -> bool: # value checks if rule["operator"].upper() not in VALID_OPERATORS: raise FilterError("rule operator is not a valid operator.") - try: # check if method exists - method = getattr(obj, rule["criterion"]) - except: + if not hasattr(obj, rule["criterion"]): raise FilterError(f"method {rule['criterion']} does not exist in obj.") + method = getattr(obj, rule["criterion"]) # check if method is decorated with @filter_criterion if not isinstance(obj, ObjectWrapper): if callable(method) and not hasattr(method, "_is_whitelisted"): @@ -685,11 +684,7 @@ def method(*args, **kwargs): raise AttributeError(f"Not all objects have the attribute '{name}'") else: if hasattr(self._obj, name): - attr = getattr(self._obj, name) # If the attribute is a method, return it directly - if callable(attr): - return attr - else: - return attr + return getattr(self._obj, name) else: raise AttributeError(f"'{type(self._obj).__name__}' object has no attribute '{name}'")