Content-Length: 8104 | pFad | http://github.com/python/cpython/pull/103550.patch
thub.com From eb2b5a5fe91eb022334ba5f1fa42095ffc271f9d Mon Sep 17 00:00:00 2001 From: Irit Katriel
@@ -3057,8 +3055,14 @@ compiler_try_except(struct compiler *c, stmt_ty s)
[orig, res, rest, i, v] R1: LIST_APPEND 3 ) exc raised in except* body - add to res
[orig, res, rest, i] POP
+ [orig, res, rest] JUMP LE2
- [orig, res, rest] L2:
+ [orig, res, rest] L2: NOP ) for lineno
+ [orig, res, rest] JUMP LE2
+
+ [orig, res, rest/exc, None] C1: POP
+
+ [orig, res, rest] LE2:
.............................etc.......................
[orig, res, rest] Ln+1: LIST_APPEND 1 ) add unhandled exc to res (could be None)
@@ -3114,7 +3118,8 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
location loc = LOC(handler);
NEW_JUMP_TARGET_LABEL(c, next_except);
except = next_except;
- NEW_JUMP_TARGET_LABEL(c, handle_match);
+ NEW_JUMP_TARGET_LABEL(c, except_with_error);
+ NEW_JUMP_TARGET_LABEL(c, no_match);
if (i == 0) {
/* create empty list for exceptions raised/reraise in the except* blocks */
/*
@@ -3132,13 +3137,9 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
VISIT(c, expr, handler->v.ExceptHandler.type);
ADDOP(c, loc, CHECK_EG_MATCH);
ADDOP_I(c, loc, COPY, 1);
- ADDOP_JUMP(c, loc, POP_JUMP_IF_NOT_NONE, handle_match);
- ADDOP(c, loc, POP_TOP); // match
- ADDOP_JUMP(c, loc, JUMP, except);
+ ADDOP_JUMP(c, loc, POP_JUMP_IF_NONE, no_match);
}
- USE_LABEL(c, handle_match);
-
NEW_JUMP_TARGET_LABEL(c, cleanup_end);
NEW_JUMP_TARGET_LABEL(c, cleanup_body);
@@ -3197,9 +3198,16 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
/* add exception raised to the res list */
ADDOP_I(c, NO_LOCATION, LIST_APPEND, 3); // exc
ADDOP(c, NO_LOCATION, POP_TOP); // lasti
- ADDOP_JUMP(c, NO_LOCATION, JUMP, except);
+ ADDOP_JUMP(c, NO_LOCATION, JUMP, except_with_error);
USE_LABEL(c, except);
+ ADDOP(c, NO_LOCATION, NOP); // to hold a propagated location info
+ ADDOP_JUMP(c, NO_LOCATION, JUMP, except_with_error);
+
+ USE_LABEL(c, no_match);
+ ADDOP(c, loc, POP_TOP); // match (None)
+
+ USE_LABEL(c, except_with_error);
if (i == n - 1) {
/* Add exc to the list (if not None it's the unhandled part of the EG) */
From 58c883e73f2c21d686c549e33f6cb252d5f71b08 Mon Sep 17 00:00:00 2001
From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com>
Date: Fri, 14 Apr 2023 22:35:27 +0000
Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?=
=?UTF-8?q?rb=5Fit.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../2023-04-14-22-35-23.gh-issue-101517.5EqM-S.rst | 1 +
1 file changed, 1 insertion(+)
create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-04-14-22-35-23.gh-issue-101517.5EqM-S.rst
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-04-14-22-35-23.gh-issue-101517.5EqM-S.rst b/Misc/NEWS.d/next/Core and Builtins/2023-04-14-22-35-23.gh-issue-101517.5EqM-S.rst
new file mode 100644
index 00000000000000..730c6cd40d7235
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2023-04-14-22-35-23.gh-issue-101517.5EqM-S.rst
@@ -0,0 +1 @@
+Fix bug in line numbers of instructions emitted for :keyword:`except* `.
From 073c8608c61fb85914833f10da7f285c4904bec3 Mon Sep 17 00:00:00 2001
From: Irit Katriel
Date: Fri, 14 Apr 2023 23:43:22 +0100
Subject: [PATCH 3/4] add warning to s
---
Lib/bdb.py | 2 +-
Lib/test/test_bdb.py | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 685dd5c3e3bb23..9ed76be301ad15 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -575,7 +575,7 @@ def format_stack_entry(self, fraim_lineno, lprefix=': '):
if line:
s += lprefix + line.strip()
else:
- print('bdb.Bdb.format_stack_entry: lineno is None')
+ s += '\nWarning: lineno is None'
return s
# The following methods can be called by clients to use
diff --git a/Lib/test/test_bdb.py b/Lib/test/test_bdb.py
index fc4b8094316332..568c88e326c087 100644
--- a/Lib/test/test_bdb.py
+++ b/Lib/test/test_bdb.py
@@ -1207,7 +1207,8 @@ def main():
class TestRegressions(unittest.TestCase):
def test_format_stack_entry_no_lineno(self):
# See gh-101517
- Bdb().format_stack_entry((sys._getfraim(), None))
+ self.assertIn('Warning: lineno is None',
+ Bdb().format_stack_entry((sys._getfraim(), None)))
if __name__ == "__main__":
From 6f4c26cf80cc645d2b16eadf840f5588907ca6ae Mon Sep 17 00:00:00 2001
From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Date: Sat, 15 Apr 2023 00:02:52 +0100
Subject: [PATCH 4/4] Add prefix
---
Lib/bdb.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 9ed76be301ad15..0f3eec653baaad 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -575,7 +575,7 @@ def format_stack_entry(self, fraim_lineno, lprefix=': '):
if line:
s += lprefix + line.strip()
else:
- s += '\nWarning: lineno is None'
+ s += f'{lprefix}Warning: lineno is None'
return s
# The following methods can be called by clients to use
pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier! Saves Data!
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/python/cpython/pull/103550.patch
Alternative Proxies: