mirror of
https://github.com/python/cpython.git
synced 2025-08-14 22:01:08 +00:00
bpo-44297: Fix missing line number in generator expressions (GH-26821)
* Make sure that line number is set when entering comprehension scope in compiler.
(cherry picked from commit 82e5c28af7
)
This commit is contained in:
parent
553e10498a
commit
7674c83d81
4 changed files with 978 additions and 959 deletions
|
@ -895,6 +895,21 @@ if 1:
|
||||||
for (_, _, line) in func.__code__.co_lines() ]
|
for (_, _, line) in func.__code__.co_lines() ]
|
||||||
self.assertEqual(lines, code_lines)
|
self.assertEqual(lines, code_lines)
|
||||||
|
|
||||||
|
def test_line_number_genexp(self):
|
||||||
|
|
||||||
|
def return_genexp():
|
||||||
|
return (1
|
||||||
|
for
|
||||||
|
x
|
||||||
|
in
|
||||||
|
y)
|
||||||
|
genexp_lines = [None, 1, 3, 1]
|
||||||
|
|
||||||
|
genexp_code = return_genexp.__code__.co_consts[1]
|
||||||
|
code_lines = [None if line is None else line-return_genexp.__code__.co_firstlineno
|
||||||
|
for (_, _, line) in genexp_code.co_lines() ]
|
||||||
|
self.assertEqual(genexp_lines, code_lines)
|
||||||
|
|
||||||
|
|
||||||
def test_big_dict_literal(self):
|
def test_big_dict_literal(self):
|
||||||
# The compiler has a flushing point in "compiler_dict" that calls compiles
|
# The compiler has a flushing point in "compiler_dict" that calls compiles
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Make sure that the line number is set when entering a comprehension scope.
|
||||||
|
Ensures that backtraces inclusing generator expressions show the correct
|
||||||
|
line number.
|
|
@ -4799,6 +4799,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
|
||||||
{
|
{
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
SET_LOC(c, e);
|
||||||
|
|
||||||
is_async_generator = c->u->u_ste->ste_coroutine;
|
is_async_generator = c->u->u_ste->ste_coroutine;
|
||||||
|
|
||||||
|
|
1918
Python/importlib_external.h
generated
1918
Python/importlib_external.h
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue