8000 bpo-46331: Do not set line number of instruction storing doc-string. … · python/cpython@bd04fac · GitHub
[go: up one dir, main page]

Skip to content

Commit bd04fac

Browse files
authored
bpo-46331: Do not set line number of instruction storing doc-string. (GH-30518)
1 parent ea1a545 commit bd04fac

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Lib/test/test_sys_settrace.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,25 @@ def func():
14031403
(3, 'line'),
14041404
(3, 'return')])
14051405

1406+
def test_class_creation_with_docstrings(self):
1407+
1408+
def func():
1409+
class Class_1:
1410+
''' the docstring. 2'''
1411+
def __init__(self):
1412+
''' Another docstring. 4'''
1413+
self.a = 5
1414+
1415+
self.run_and_compare(func,
1416+
[(0, 'call'),
1417+
(1, 'line'),
1418+
(1, 'call'),
1419+
(1, 'line'),
1420+
(2, 'line'),
1421+
(3, 'line'),
1422+
(3, 'return'),
1423+
(1, 'return')])
1424+
14061425

14071426
class SkipLineEventsTraceTestCase(TraceTestCase):
14081427
"""Repeat the trace tests, but with per-line events skipped"""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Do not set line number of instruction storing doc-string. Fixes regression
2+
introduced in 3.11 alpha.

Python/compile.c

+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,7 @@ compiler_body(struct compiler *c, asdl_stmt_seq *stmts)
20342034
st = (stmt_ty)asdl_seq_GET(stmts, 0);
20352035
assert(st->kind == Expr_kind);
20362036
VISIT(c, expr, st->v.Expr.value);
2037+
UNSET_LOC(c);
20372038
if (!compiler_nameop(c, __doc__, Store))
20382039
return 0;
20392040
}

0 commit comments

Comments
 (0)
0