|
17 | 17 | freevars: ()
|
18 | 18 | nlocals: 2
|
19 | 19 | flags: 3
|
| 20 | +lnotab: [4, 1, 10, 2] |
20 | 21 | consts: ('None', '<code object g>')
|
21 | 22 |
|
22 | 23 | >>> dump(f(4).__code__)
|
|
30 | 31 | freevars: ('x',)
|
31 | 32 | nlocals: 1
|
32 | 33 | flags: 19
|
| 34 | +lnotab: [4, 1] |
33 | 35 | consts: ('None',)
|
34 | 36 |
|
35 | 37 | >>> def h(x, y):
|
|
50 | 52 | freevars: ()
|
51 | 53 | nlocals: 5
|
52 | 54 | flags: 3
|
| 55 | +lnotab: [2, 1, 10, 1, 10, 1, 10, 1] |
53 | 56 | consts: ('None',)
|
54 | 57 |
|
55 | 58 | >>> def attrs(obj):
|
|
68 | 71 | freevars: ()
|
69 | 72 | nlocals: 1
|
70 | 73 | flags: 3
|
| 74 | +lnotab: [2, 1, 46, 1, 46, 1] |
71 | 75 | consts: ('None',)
|
72 | 76 |
|
73 | 77 | >>> def optimize_away():
|
|
87 | 91 | freevars: ()
|
88 | 92 | nlocals: 0
|
89 | 93 | flags: 3
|
| 94 | +lnotab: [2, 2, 2, 1, 2, 1] |
90 | 95 | consts: ("'doc string'", 'None')
|
91 | 96 |
|
92 | 97 | >>> def keywordonly_args(a,b,*,k1):
|
|
104 | 109 | freevars: ()
|
105 | 110 | nlocals: 3
|
106 | 111 | flags: 3
|
| 112 | +lnotab: [2, 1] |
107 | 113 | consts: ('None',)
|
108 | 114 |
|
109 | 115 | >>> def posonly_args(a,b,/,c):
|
|
121 | 127 | freevars: ()
|
122 | 128 | nlocals: 3
|
123 | 129 | flags: 3
|
| 130 | +lnotab: [2, 1] |
124 | 131 | consts: ('None',)
|
125 | 132 |
|
126 | 133 | """
|
@@ -161,6 +168,7 @@ def dump(co):
|
161 | 168 | "kwonlyargcount", "names", "varnames",
|
162 | 169 | "cellvars", "freevars", "nlocals", "flags"]:
|
163 | 170 | print("%s: %s" % (attr, getattr(co, "co_" + attr)))
|
| 171 | + print("lnotab:", list(co.co_lnotab)) |
164 | 172 | print("consts:", tuple(consts(co.co_consts)))
|
165 | 173 |
|
166 | 174 | # Needed for test_closure_injection below
|
@@ -428,6 +436,21 @@ def func():
|
428 | 436 | self.assertIsNone(line)
|
429 | 437 | self.assertEqual(end_line, new_code.co_firstlineno + 1)
|
430 | 438 |
|
| 439 | + def test_large_lnotab(self): |
| 440 | + d = {} |
| 441 | + lines = ( |
| 442 | + ["def f():"] + |
| 443 | + [""] * (1 << 17) + |
| 444 | + [" pass"] * (1 << 17) |
| 445 | + ) |
| 446 | + source = "\n".join(lines) |
| 447 | + exec(source, d) |
| 448 | + code = d["f"].__code__ |
| 449 | + |
| 450 | + expected = 1032 * [0, 127] + [0, 9] + ((1 << 17) - 1) * [2, 1] |
| 451 | + expected[0] = 2 |
| 452 | + self.assertEqual(list(code.co_lnotab), expected) |
| 453 | + |
431 | 454 |
|
432 | 455 | def isinterned(s):
|
433 | 456 | return s is sys.intern(('_' + s + '_')[1:-1])
|
|
0 commit comments