Skip to content

Commit 28d629b

Browse files
committed
parametrise log_method_calls decorator for excluding logging of properties, private methods, and dunders
1 parent dc0bca7 commit 28d629b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

todoist_api_python/_core/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ def wrapper(*args, **kwargs):
107107
return wrapper
108108

109109

110-
def log_method_calls(exclude_dunder: bool = True) -> Callable[[type], type]:
110+
def log_method_calls(
111+
exclude_properties: bool = True, exclude_private: bool = True, exclude_dunder: bool = True
112+
) -> Callable[[type], type]:
111113
"""
112114
Class decorator to log calls to all methods of a class. Arguments and returned values are
113115
included in the log.
@@ -121,6 +123,10 @@ def class_decorator(cls: type) -> type:
121123
if callable(attr_value):
122124
if exclude_dunder and attr_name.startswith("__") and attr_name.endswith("__"):
123125
continue
126+
if exclude_private and attr_name.startswith("_"):
127+
continue
128+
if exclude_properties and isinstance(getattr(cls, attr_name, None), property):
129+
continue
124130
decorated_attr = log_calls(attr_value)
125131
setattr(cls, attr_name, decorated_attr)
126132
return cls

todoist_api_python/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
ViewStyle = Annotated[str, Predicate(lambda x: x in ("list", "board", "calendar"))]
8686

8787

88-
@log_method_calls(exclude_dunder=True)
88+
@log_method_calls()
8989
class TodoistAPI:
9090
"""
9191
Client for the Todoist API.

0 commit comments

Comments
 (0)