summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-01-15 13:52:00 +0000
committerGitHub <noreply@github.com>2021-01-15 13:52:00 +0000
commite56d54e447694c6ced2093d2273c3e3d60b36b6f (patch)
treead30807810f6be60a8a51910a6beb80ecd5c3db5
parentbpo-42877: add the 'compact' param to TracebackException's __init__ (#24179) (diff)
downloadcpython-e56d54e447694c6ced2093d2273c3e3d60b36b6f.tar.gz
cpython-e56d54e447694c6ced2093d2273c3e3d60b36b6f.tar.bz2
cpython-e56d54e447694c6ced2093d2273c3e3d60b36b6f.zip
Mark instructions at end of class scope as artificial. (GH-24222)
-rw-r--r--Lib/test/test_sys_settrace.py18
-rw-r--r--Python/compile.c2
2 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
index 42989862502..49e89289956 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -956,6 +956,24 @@ class TraceTestCase(unittest.TestCase):
(2, 'line'),
(2, 'return')])
+ def test_implicit_return_in_class(self):
+
+ def func():
+ class A:
+ if 3 < 9:
+ a = 1
+ else:
+ a = 2
+
+ self.run_and_compare(func,
+ [(0, 'call'),
+ (1, 'line'),
+ (1, 'call'),
+ (1, 'line'),
+ (2, 'line'),
+ (3, 'line'),
+ (3, 'return'),
+ (1, 'return')])
class SkipLineEventsTraceTestCase(TraceTestCase):
"""Repeat the trace tests, but with per-line events skipped"""
diff --git a/Python/compile.c b/Python/compile.c
index d373d8a4061..6aa74cc2d67 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -2371,6 +2371,8 @@ compiler_class(struct compiler *c, stmt_ty s)
compiler_exit_scope(c);
return 0;
}
+ /* The following code is artificial */
+ c->u->u_lineno = -1;
/* Return __classcell__ if it is referenced, otherwise return None */
if (c->u->u_ste->ste_needs_class_closure) {
/* Store __classcell__ into class namespace & return it */