Closed RBerga06 closed 1 year ago
This is a very interesting and useful feature, however it probably requires a way to attach information to the function. Currently, the decorator
API does not have this capability, because it's not always safe to setattr(...)
something on unknown functions.
Maybe debug
isn't the right name...
Probably call_info
is better.
Ok, so this is what we want:
@call_info()
def foo(throws: bool) -> None:
if throws: raise
foo(False)
try:
foo(True) # this raises
except:
pass
foo_calls = call_info.get(foo)
reveal_type(foo_calls) # list[CallInfo]
call0 = foo_calls[0]
call1 = foo_calls[1]
call0.args # (False, )
call1.args # (True, )
call0.kwargs # {}
call1.kwargs # {}
call0.success # True
call1.success # False
call0.result # None
call1.result # RuntimeError
We could also introduce a parameter to control logging behaviour:
@call_info(log=False) # by default, log=True
def foo(throws: bool) -> None:
if throws: raise
Is your feature request related to a problem? Please describe. It would be very useful, especially when debugging, to be able to retrieve detailed information about a function at runtime (maybe even log every call).
Describe the solution you'd like A new
debug
decorator would be nice:Describe alternatives you've considered N/A
Additional context N/A