]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-123142: fix too wide source location of GET_ITER/GET_AITER (#123420)
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Wed, 28 Aug 2024 16:11:52 +0000 (17:11 +0100)
committerGitHub <noreply@github.com>
Wed, 28 Aug 2024 16:11:52 +0000 (17:11 +0100)
Lib/test/support/__init__.py
Lib/test/test_dictcomps.py
Lib/test/test_iter.py
Lib/test/test_listcomps.py
Lib/test/test_setcomps.py
Python/compile.c

index 19bbd40e2e67d509a69e65cd20ac07f013000f57..3149fd732f64a784521a38162c98a056c6a33c61 100644 (file)
@@ -2850,14 +2850,17 @@ def get_signal_name(exitcode):
     return None
 
 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:
             1/0
         self.next_raises = next_raises
+        self.iter_raises = iter_raises
 
     def __next__(self):
         if self.next_raises:
             1/0
 
     def __iter__(self):
+        if self.iter_raises:
+            1/0
         return self
index e9df2967627240fafcfb6e07fed673172577e261..26b56dac5032fa8ecf3738e037bb113ae1425b21 100644 (file)
@@ -145,8 +145,15 @@ class DictComprehensionTest(unittest.TestCase):
             except Exception as 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)"),
                                (next_raises, "BrokenIter(next_raises=True)"),
+                               (iter_raises, "BrokenIter(iter_raises=True)"),
                               ]:
             with self.subTest(func):
                 exc = func()
index 502856e3e2fbe006cab40754b084619c9f901f76..1b9f3cf76240ad4e33189070dddd162648d95680 100644 (file)
@@ -1163,8 +1163,16 @@ class TestCase(unittest.TestCase):
             except Exception as 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)"),
                                (next_raises, "BrokenIter(next_raises=True)"),
+                               (iter_raises, "BrokenIter(iter_raises=True)"),
                               ]:
             with self.subTest(func):
                 exc = func()
index 467e0c5ea12982abfa72df30ecab18686f274436..45644d6c0927827c4f1c3663082f1c98be5e5abb 100644 (file)
@@ -730,8 +730,15 @@ class ListComprehensionTest(unittest.TestCase):
             except Exception as 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)"),
                                (next_raises, "BrokenIter(next_raises=True)"),
+                               (iter_raises, "BrokenIter(iter_raises=True)"),
                               ]:
             with self.subTest(func):
                 exc = func()
index ba4173cd6a7dd70497f8243f890ea088ce9b56b5..0bb02ef11f6b4b99e00f316cbb44cc060972d9a9 100644 (file)
@@ -168,8 +168,15 @@ class SetComprehensionTest(unittest.TestCase):
             except Exception as 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)"),
                                (next_raises, "BrokenIter(next_raises=True)"),
+                               (iter_raises, "BrokenIter(iter_raises=True)"),
                               ]:
             with self.subTest(func):
                 exc = func()
index 3464723104f1b4ca0a7958437e0805dca7d88cc9..3d6bc7eb2f8169a00e9a34f510f65d355bb4c8b4 100644 (file)
@@ -2990,7 +2990,7 @@ codegen_async_for(struct compiler *c, stmt_ty s)
     NEW_JUMP_TARGET_LABEL(c, end);
 
     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);
     RETURN_IF_ERROR(compiler_push_fblock(c, loc, FOR_LOOP, start, end, NULL));
@@ -5284,7 +5284,7 @@ codegen_async_comprehension_generator(struct compiler *c, location loc,
         else {
             /* Sub-iter - calculate on the fly */
             VISIT(c, expr, gen->iter);
-            ADDOP(c, loc, GET_AITER);
+            ADDOP(c, LOC(gen->iter), GET_AITER);
         }
     }
 
@@ -5618,15 +5618,14 @@ pop_inlined_comprehension_state(struct compiler *c, location loc,
 }
 
 static inline int
-codegen_comprehension_iter(struct compiler *c, location loc,
-                           comprehension_ty comp)
+codegen_comprehension_iter(struct compiler *c, comprehension_ty comp)
 {
     VISIT(c, expr, comp->iter);
     if (comp->is_async) {
-        ADDOP(c, loc, GET_AITER);
+        ADDOP(c, LOC(comp->iter), GET_AITER);
     }
     else {
-        ADDOP(c, loc, GET_ITER);
+        ADDOP(c, LOC(comp->iter), GET_ITER);
     }
     return SUCCESS;
 }
@@ -5654,7 +5653,7 @@ codegen_comprehension(struct compiler *c, expr_ty e, int type,
 
     outermost = (comprehension_ty) asdl_seq_GET(generators, 0);
     if (is_inlined) {
-        if (codegen_comprehension_iter(c, loc, outermost)) {
+        if (codegen_comprehension_iter(c, outermost)) {
             goto error;
         }
         if (push_inlined_comprehension_state(c, loc, entry, &inline_state)) {
@@ -5736,7 +5735,7 @@ codegen_comprehension(struct compiler *c, expr_ty e, int type,
     }
     Py_CLEAR(co);
 
-    if (codegen_comprehension_iter(c, loc, outermost)) {
+    if (codegen_comprehension_iter(c, outermost)) {
         goto error;
     }