mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] gh-123142: fix too wide source location of GET_ITER/GET_AITER (GH-123420). (#123436)
(cherry picked from commit 61bef6245c
)
This commit is contained in:
parent
ccc6c2b8c0
commit
0181aa2e3e
6 changed files with 40 additions and 9 deletions
|
@ -2472,14 +2472,17 @@ def iter_slot_wrappers(cls):
|
||||||
|
|
||||||
|
|
||||||
class BrokenIter:
|
class BrokenIter:
|
||||||
def __init__(self, init_raises=False, next_raises=False):
|
def __init__(self, init_raises=False, next_raises=False, iter_raises=False):
|
||||||
if init_raises:
|
if init_raises:
|
||||||
1/0
|
1/0
|
||||||
self.next_raises = next_raises
|
self.next_raises = next_raises
|
||||||
|
self.iter_raises = iter_raises
|
||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
if self.next_raises:
|
if self.next_raises:
|
||||||
1/0
|
1/0
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
|
if self.iter_raises:
|
||||||
|
1/0
|
||||||
return self
|
return self
|
||||||
|
|
|
@ -145,8 +145,15 @@ class DictComprehensionTest(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return e
|
return e
|
||||||
|
|
||||||
|
def iter_raises():
|
||||||
|
try:
|
||||||
|
{x:x for x in BrokenIter(iter_raises=True)}
|
||||||
|
except Exception as e:
|
||||||
|
return e
|
||||||
|
|
||||||
for func, expected in [(init_raises, "BrokenIter(init_raises=True)"),
|
for func, expected in [(init_raises, "BrokenIter(init_raises=True)"),
|
||||||
(next_raises, "BrokenIter(next_raises=True)"),
|
(next_raises, "BrokenIter(next_raises=True)"),
|
||||||
|
(iter_raises, "BrokenIter(iter_raises=True)"),
|
||||||
]:
|
]:
|
||||||
with self.subTest(func):
|
with self.subTest(func):
|
||||||
exc = func()
|
exc = func()
|
||||||
|
|
|
@ -1163,8 +1163,16 @@ class TestCase(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return e
|
return e
|
||||||
|
|
||||||
|
def iter_raises():
|
||||||
|
try:
|
||||||
|
for x in BrokenIter(iter_raises=True):
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
return e
|
||||||
|
|
||||||
for func, expected in [(init_raises, "BrokenIter(init_raises=True)"),
|
for func, expected in [(init_raises, "BrokenIter(init_raises=True)"),
|
||||||
(next_raises, "BrokenIter(next_raises=True)"),
|
(next_raises, "BrokenIter(next_raises=True)"),
|
||||||
|
(iter_raises, "BrokenIter(iter_raises=True)"),
|
||||||
]:
|
]:
|
||||||
with self.subTest(func):
|
with self.subTest(func):
|
||||||
exc = func()
|
exc = func()
|
||||||
|
|
|
@ -725,8 +725,15 @@ class ListComprehensionTest(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return e
|
return e
|
||||||
|
|
||||||
|
def iter_raises():
|
||||||
|
try:
|
||||||
|
[x for x in BrokenIter(iter_raises=True)]
|
||||||
|
except Exception as e:
|
||||||
|
return e
|
||||||
|
|
||||||
for func, expected in [(init_raises, "BrokenIter(init_raises=True)"),
|
for func, expected in [(init_raises, "BrokenIter(init_raises=True)"),
|
||||||
(next_raises, "BrokenIter(next_raises=True)"),
|
(next_raises, "BrokenIter(next_raises=True)"),
|
||||||
|
(iter_raises, "BrokenIter(iter_raises=True)"),
|
||||||
]:
|
]:
|
||||||
with self.subTest(func):
|
with self.subTest(func):
|
||||||
exc = func()
|
exc = func()
|
||||||
|
|
|
@ -168,8 +168,15 @@ class SetComprehensionTest(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return e
|
return e
|
||||||
|
|
||||||
|
def iter_raises():
|
||||||
|
try:
|
||||||
|
{x for x in BrokenIter(iter_raises=True)}
|
||||||
|
except Exception as e:
|
||||||
|
return e
|
||||||
|
|
||||||
for func, expected in [(init_raises, "BrokenIter(init_raises=True)"),
|
for func, expected in [(init_raises, "BrokenIter(init_raises=True)"),
|
||||||
(next_raises, "BrokenIter(next_raises=True)"),
|
(next_raises, "BrokenIter(next_raises=True)"),
|
||||||
|
(iter_raises, "BrokenIter(iter_raises=True)"),
|
||||||
]:
|
]:
|
||||||
with self.subTest(func):
|
with self.subTest(func):
|
||||||
exc = func()
|
exc = func()
|
||||||
|
|
|
@ -3069,7 +3069,7 @@ compiler_async_for(struct compiler *c, stmt_ty s)
|
||||||
NEW_JUMP_TARGET_LABEL(c, end);
|
NEW_JUMP_TARGET_LABEL(c, end);
|
||||||
|
|
||||||
VISIT(c, expr, s->v.AsyncFor.iter);
|
VISIT(c, expr, s->v.AsyncFor.iter);
|
||||||
ADDOP(c, loc, GET_AITER);
|
ADDOP(c, LOC(s->v.AsyncFor.iter), GET_AITER);
|
||||||
|
|
||||||
USE_LABEL(c, start);
|
USE_LABEL(c, start);
|
||||||
RETURN_IF_ERROR(compiler_push_fblock(c, loc, FOR_LOOP, start, end, NULL));
|
RETURN_IF_ERROR(compiler_push_fblock(c, loc, FOR_LOOP, start, end, NULL));
|
||||||
|
@ -5367,7 +5367,7 @@ compiler_async_comprehension_generator(struct compiler *c, location loc,
|
||||||
else {
|
else {
|
||||||
/* Sub-iter - calculate on the fly */
|
/* Sub-iter - calculate on the fly */
|
||||||
VISIT(c, expr, gen->iter);
|
VISIT(c, expr, gen->iter);
|
||||||
ADDOP(c, loc, GET_AITER);
|
ADDOP(c, LOC(gen->iter), GET_AITER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5652,15 +5652,14 @@ pop_inlined_comprehension_state(struct compiler *c, location loc,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
compiler_comprehension_iter(struct compiler *c, location loc,
|
compiler_comprehension_iter(struct compiler *c, comprehension_ty comp)
|
||||||
comprehension_ty comp)
|
|
||||||
{
|
{
|
||||||
VISIT(c, expr, comp->iter);
|
VISIT(c, expr, comp->iter);
|
||||||
if (comp->is_async) {
|
if (comp->is_async) {
|
||||||
ADDOP(c, loc, GET_AITER);
|
ADDOP(c, LOC(comp->iter), GET_AITER);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ADDOP(c, loc, GET_ITER);
|
ADDOP(c, LOC(comp->iter), GET_ITER);
|
||||||
}
|
}
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -5686,7 +5685,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
|
||||||
|
|
||||||
outermost = (comprehension_ty) asdl_seq_GET(generators, 0);
|
outermost = (comprehension_ty) asdl_seq_GET(generators, 0);
|
||||||
if (is_inlined) {
|
if (is_inlined) {
|
||||||
if (compiler_comprehension_iter(c, loc, outermost)) {
|
if (compiler_comprehension_iter(c, outermost)) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (push_inlined_comprehension_state(c, loc, entry, &inline_state)) {
|
if (push_inlined_comprehension_state(c, loc, entry, &inline_state)) {
|
||||||
|
@ -5772,7 +5771,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
|
||||||
}
|
}
|
||||||
Py_CLEAR(co);
|
Py_CLEAR(co);
|
||||||
|
|
||||||
if (compiler_comprehension_iter(c, loc, outermost)) {
|
if (compiler_comprehension_iter(c, outermost)) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue