You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from __future__ importprint_functionimportpysnooper@pysnooper.snoop()deffact(n):
ifn==1:
return1returnn*fact(n-1)
defmain():
print(fact(3))
if__name__=='__main__':
main()
Output:
$ python mytest2.py
Starting var:.. n = 3
01:22:43.094346 call 4 @pysnooper.snoop()
01:22:43.095271 line 6 if n == 1:
01:22:43.095435 line 8 return n * fact(n - 1)
Starting var:.. n = 2
01:22:43.095591 call 4 @pysnooper.snoop()
01:22:43.095664 line 6 if n == 1:
01:22:43.095722 line 8 return n * fact(n - 1)
Starting var:.. n = 1
01:22:43.095830 call 4 @pysnooper.snoop()
01:22:43.095884 line 6 if n == 1:
01:22:43.095941 line 7 return 1
01:22:43.096022 return 7 return 1
01:22:43.096110 return 8 return n * fact(n - 1)
01:22:43.096175 return 8 return n * fact(n - 1)
6
When setting depth=2, it even raised an error:
Starting var:.. n = 3
01:26:47.652684 call 4 @pysnooper.snoop(depth=2)
01:26:47.653612 line 6 if n == 1:
01:26:47.653684 line 8 return n * fact(n - 1)
Starting var:.. n = 2
Traceback (most recent call last):
File "mytest2.py", line 14, in<module>main()
File "mytest2.py", line 11, in main
print(fact(3))
File "</home/xiaofei/.local/lib/python2.7/site-packages/decorator.pyc:decorator-gen-2>", line 2, in fact
File "/home/xiaofei/.local/lib/python2.7/site-packages/pysnooper/pysnooper.py", line 72, in decorate
return function(*args, **kwargs)
File "mytest2.py", line 8, in fact
return n * fact(n - 1)
File "</home/xiaofei/.local/lib/python2.7/site-packages/decorator.pyc:decorator-gen-2>", line 1, in fact
File "/home/xiaofei/.local/lib/python2.7/site-packages/pysnooper/tracer.py", line 182, in trace
source_line = get_source_from_frame(frame)[frame.f_lineno - 1]
File "/home/xiaofei/.local/lib/python2.7/site-packages/pysnooper/tracer.py", line 75, in get_source_from_frame
raise NotImplementedError
NotImplementedError
The text was updated successfully, but these errors were encountered:
cool-RR
changed the title
"depth" cannot deal with recursive function
Feature request: support recursion, including with depth argument
Apr 22, 2019
This works now. I'm guessing the error was essentially the same issue encountered in #109 and fixed in #112. Making the output look a little nicer is being worked on in #108, although I don't think it needs to be merged to count this as fixed.
For example:
Output:
When setting
depth=2
, it even raised an error:The text was updated successfully, but these errors were encountered: