Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/object_filtering/object_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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}'")