cool-RR / PySnooper

Never use print for debugging again
MIT License
16.31k stars 954 forks source link

No variable output from the last line #237

Open webber26232 opened 1 year ago

webber26232 commented 1 year ago

Hi, I found that the variable, new or modified, in the last line will not be shown. Below is the same example with the print removed:

import pysnooper
import random

def foo():
    lst = []
    for i in range(10):
        lst.append(random.randrange(1, 1000))

    with pysnooper.snoop():
        lower = min(lst)
        upper = max(lst)
        mid = (lower + upper) / 2

foo()

which outputs something like:

New var:....... lst = [379, 800, 331, 57, 210, 524, 525, 837, 118, 810]
New var:....... i = 9
22:46:58.874665 line        10         lower = min(lst)
New var:....... lower = 57
22:46:58.876660 line        11         upper = max(lst)
New var:....... upper = 837
22:46:58.876660 line        12         mid = (lower + upper) / 2
Elapsed time: 00:00:00.003000

We can find that the variable mid was not printed. Please let me know if this is expected.

cool-RR commented 1 year ago

It is not expected. However, it doesn't reproduce for me:

Source path:... C:\Users\Administrator\Desktop\ass.py
New var:....... lst = [615, 725, 892, 822, 832, 521, 9, 195, 356, 904]
New var:....... i = 9
12:29:32.836714 line        10         lower = min(lst)
New var:....... lower = 9
12:29:32.836714 line        11         upper = max(lst)
New var:....... upper = 904
12:29:32.836714 line        12         mid = (lower + upper) / 2
New var:....... mid = 456.5
12:29:32.836714 line         9     with pysnooper.snoop():
Elapsed time: 00:00:00.000999

I'm on Python 3.10.10 on Windows 10 and PySnooper==1.1.1. What about you?

webber26232 commented 1 year ago

My env is Python 3.9.13 on Windows 10 and PySnooper==1.1.1

cool-RR commented 1 year ago

I see. This is indeed a bug but too low priority for me to work on. If you or anyone else want to try to understand what's happening and fix it, go ahead. Thanks for reporting.