New issue 3076: First line traced in a nested structure depends on the length of the structure https://bitbucket.org/pypy/pypy/issues/3076/first-line-traced-in-a-nested-structure
Ned Batchelder: When creating a nested list, the settrace trace function is called with a “call” event. The list looks like: ``` data = [ [ 0 ], [ 1 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ], [ 6 ], [ 7 ], [ 8 ], [ 9 ], ] ``` With PyPy 3.x, the call event is on line 1. With PyPy 2.x, the location of the call event depends on the length of the list. If the list is short \(10 elements\), the call event is on line 2, or if the list were more deeply nested, it would be whatever line had the first integer. If the list is long \(2000 elements\), the call event is on line 1. It seems wrong that the length of the list would change the call event. Code to demonstrate the problem: ``` $ cat make_file.py import sys num = int(sys.argv[1]) print("data = [") for i in range(num): print(" [ {} ],".format(i)) print("]") print("print(len(data))") $ python make_file.py 10 > short.py $ python make_file.py 2000 > long.py $ cat run.py import os import sys print(sys.version) blacklist = ["frozen", "_structseq", "utf_8"] def trace(frame, event, arg): if event == 'call': fname = os.path.basename(frame.f_code.co_filename) noise = any(bword in fname for bword in blacklist) if not noise: print("Call {}:{}".format(fname, frame.f_lineno)) return trace sys.settrace(trace) print("short:") import short print("long:") import long $ pypy2 run.py 2.7.13 (8cdda8b8cdb8, Apr 14 2019, 14:06:58) [PyPy 7.1.1 with GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] short: Call short.py:2 10 long: Call long.py:1 2000 Call app_main.py:96 $ pypy3 run.py 3.6.1 (784b254d6699, Apr 14 2019, 10:22:55) [PyPy 7.1.1-beta0 with GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] short: Call short.py:1 10 long: Call long.py:1 2000 Call app_main.py:100 $ cat short.py data = [ [ 0 ], [ 1 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ], [ 6 ], [ 7 ], [ 8 ], [ 9 ], ] print(len(data)) $ ``` _______________________________________________ pypy-issue mailing list pypy-issue@python.org https://mail.python.org/mailman/listinfo/pypy-issue