MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / log

Function log

example_code/item_086.py:174–189  ·  view source on GitHub ↗
(func)

Source from the content-addressed store, hash-verified

172import functools
173
174def log(func):
175 @functools.wraps(func)
176 def wrapper(*args, **kwargs):
177 try:
178 result = func(*args, **kwargs)
179 except Exception as e:
180 result = e
181 raise
182 finally:
183 print(
184 f"Called {func.__name__}"
185 f"(*{args!r}, **{kwargs!r}) "
186 f"got {result!r}"
187 )
188
189 return wrapper
190
191
192print("Example 6")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected