Skip to content

Commit 0de5bc6

Browse files
committed
Merge branch 'main' into superopt
* main: gh-101517: fix line number propagation in code generated for except* (#103550) gh-103780: Use patch instead of mock in asyncio unix events test (#103782)
2 parents 19b8025 + 1c01f8d commit 0de5bc6

File tree

6 files changed

+31
-20
lines changed

6 files changed

+31
-20
lines changed

Lib/bdb.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@ def format_stack_entry(self, frame_lineno, lprefix=': '):
574574
line = linecache.getline(filename, lineno, frame.f_globals)
575575
if line:
576576
s += lprefix + line.strip()
577+
else:
578+
s += f'{lprefix}Warning: lineno is None'
577579
return s
578580

579581
# The following methods can be called by clients to use

Lib/test/test_asyncio/test_unix_events.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,11 +1712,11 @@ class PolicyTests(unittest.TestCase):
17121712
def create_policy(self):
17131713
return asyncio.DefaultEventLoopPolicy()
17141714

1715-
def test_get_default_child_watcher(self):
1715+
@mock.patch('asyncio.unix_events.can_use_pidfd')
1716+
def test_get_default_child_watcher(self, m_can_use_pidfd):
1717+
m_can_use_pidfd.return_value = False
17161718
policy = self.create_policy()
17171719
self.assertIsNone(policy._watcher)
1718-
unix_events.can_use_pidfd = mock.Mock()
1719-
unix_events.can_use_pidfd.return_value = False
17201720
with self.assertWarns(DeprecationWarning):
17211721
watcher = policy.get_child_watcher()
17221722
self.assertIsInstance(watcher, asyncio.ThreadedChildWatcher)
@@ -1725,10 +1725,9 @@ def test_get_default_child_watcher(self):
17251725
with self.assertWarns(DeprecationWarning):
17261726
self.assertIs(watcher, policy.get_child_watcher())
17271727

1728+
m_can_use_pidfd.return_value = True
17281729
policy = self.create_policy()
17291730
self.assertIsNone(policy._watcher)
1730-
unix_events.can_use_pidfd = mock.Mock()
1731-
unix_events.can_use_pidfd.return_value = True
17321731
with self.assertWarns(DeprecationWarning):
17331732
watcher = policy.get_child_watcher()
17341733
self.assertIsInstance(watcher, asyncio.PidfdChildWatcher)

Lib/test/test_bdb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,8 @@ def main():
12071207
class TestRegressions(unittest.TestCase):
12081208
def test_format_stack_entry_no_lineno(self):
12091209
# See gh-101517
1210-
Bdb().format_stack_entry((sys._getframe(), None))
1210+
self.assertIn('Warning: lineno is None',
1211+
Bdb().format_stack_entry((sys._getframe(), None)))
12111212

12121213

12131214
if __name__ == "__main__":

Lib/test/test_pdb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,8 +1715,8 @@ def test_pdb_issue_gh_101517():
17151715
... 'continue'
17161716
... ]):
17171717
... test_function()
1718-
--Return--
1719-
> <doctest test.test_pdb.test_pdb_issue_gh_101517[0]>(None)test_function()->None
1718+
> <doctest test.test_pdb.test_pdb_issue_gh_101517[0]>(5)test_function()
1719+
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
17201720
(Pdb) continue
17211721
"""
17221722

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug in line numbers of instructions emitted for :keyword:`except* <except_star>`.

Python/compile.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,20 +3067,24 @@ compiler_try_except(struct compiler *c, stmt_ty s)
30673067
[orig, res, exc] <evaluate E1>
30683068
[orig, res, exc, E1] CHECK_EG_MATCH
30693069
[orig, res, rest/exc, match?] COPY 1
3070-
[orig, res, rest/exc, match?, match?] POP_JUMP_IF_NOT_NONE H1
3071-
[orig, res, exc, None] POP_TOP
3072-
[orig, res, exc] JUMP L2
3070+
[orig, res, rest/exc, match?, match?] POP_JUMP_IF_NONE C1
30733071
3074-
[orig, res, rest, match] H1: <assign to V1> (or POP if no V1)
3072+
[orig, res, rest, match] <assign to V1> (or POP if no V1)
30753073
30763074
[orig, res, rest] SETUP_FINALLY R1
30773075
[orig, res, rest] <code for S1>
30783076
[orig, res, rest] JUMP L2
30793077
30803078
[orig, res, rest, i, v] R1: LIST_APPEND 3 ) exc raised in except* body - add to res
30813079
[orig, res, rest, i] POP
3080+
[orig, res, rest] JUMP LE2
30823081
3083-
[orig, res, rest] L2: <evaluate E2>
3082+
[orig, res, rest] L2: NOP ) for lineno
3083+
[orig, res, rest] JUMP LE2
3084+
3085+
[orig, res, rest/exc, None] C1: POP
3086+
3087+
[orig, res, rest] LE2: <evaluate E2>
30843088
.............................etc.......................
30853089
30863090
[orig, res, rest] Ln+1: LIST_APPEND 1 ) add unhandled exc to res (could be None)
@@ -3136,7 +3140,8 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
31363140
location loc = LOC(handler);
31373141
NEW_JUMP_TARGET_LABEL(c, next_except);
31383142
except = next_except;
3139-
NEW_JUMP_TARGET_LABEL(c, handle_match);
3143+
NEW_JUMP_TARGET_LABEL(c, except_with_error);
3144+
NEW_JUMP_TARGET_LABEL(c, no_match);
31403145
if (i == 0) {
31413146
/* create empty list for exceptions raised/reraise in the except* blocks */
31423147
/*
@@ -3154,13 +3159,9 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
31543159
VISIT(c, expr, handler->v.ExceptHandler.type);
31553160
ADDOP(c, loc, CHECK_EG_MATCH);
31563161
ADDOP_I(c, loc, COPY, 1);
3157-
ADDOP_JUMP(c, loc, POP_JUMP_IF_NOT_NONE, handle_match);
3158-
ADDOP(c, loc, POP_TOP); // match
3159-
ADDOP_JUMP(c, loc, JUMP, except);
3162+
ADDOP_JUMP(c, loc, POP_JUMP_IF_NONE, no_match);
31603163
}
31613164

3162-
USE_LABEL(c, handle_match);
3163-
31643165
NEW_JUMP_TARGET_LABEL(c, cleanup_end);
31653166
NEW_JUMP_TARGET_LABEL(c, cleanup_body);
31663167

@@ -3219,9 +3220,16 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
32193220
/* add exception raised to the res list */
32203221
ADDOP_I(c, NO_LOCATION, LIST_APPEND, 3); // exc
32213222
ADDOP(c, NO_LOCATION, POP_TOP); // lasti
3222-
ADDOP_JUMP(c, NO_LOCATION, JUMP, except);
3223+
ADDOP_JUMP(c, NO_LOCATION, JUMP, except_with_error);
32233224

32243225
USE_LABEL(c, except);
3226+
ADDOP(c, NO_LOCATION, NOP); // to hold a propagated location info
3227+
ADDOP_JUMP(c, NO_LOCATION, JUMP, except_with_error);
3228+
3229+
USE_LABEL(c, no_match);
3230+
ADDOP(c, loc, POP_TOP); // match (None)
3231+
3232+
USE_LABEL(c, except_with_error);
32253233

32263234
if (i == n - 1) {
32273235
/* Add exc to the list (if not None it's the unhandled part of the EG) */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy