bpo-42246: Don't forget the entry block when ensuring that all exits have a line number (GH-23636)

Don't forget the entry block when ensuring that all exits have a line number.
This commit is contained in:
Mark Shannon 2020-12-04 15:22:12 +00:00 committed by GitHub
parent f24b8101a0
commit eaccc12aa9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 4 deletions

View file

@ -809,6 +809,24 @@ def save_caller_frame():
func(save_caller_frame)
self.assertEqual(frame.f_lineno-frame.f_code.co_firstlineno, lastline)
def test_lineno_after_no_code(self):
def no_code1():
"doc string"
def no_code2():
a: int
for func in (no_code1, no_code2):
with self.subTest(func=func):
code = func.__code__
lines = list(code.co_lines())
self.assertEqual(len(lines), 1)
start, end, line = lines[0]
self.assertEqual(start, 0)
self.assertEqual(end, len(code.co_code))
self.assertEqual(line, code.co_firstlineno)
def test_big_dict_literal(self):
# The compiler has a flushing point in "compiler_dict" that calls compiles
# a portion of the dictionary literal when the loop that iterates over the items