Skip to content

Commit f68dc1c

Browse files
authored
Merge branch '3.11' into tarfile-3.11
2 parents ee503ad + d9aafe2 commit f68dc1c

File tree

8 files changed

+62
-19
lines changed

8 files changed

+62
-19
lines changed

Doc/library/dataclasses.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ Using dataclasses, *if* this code was valid::
712712

713713
@dataclass
714714
class D:
715-
x: List = []
715+
x: list = [] # This code raises ValueError
716716
def add(self, element):
717717
self.x += element
718718

Doc/library/subprocess.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,9 +921,12 @@ Reassigning them to new values is unsupported:
921921

922922
.. attribute:: Popen.returncode
923923

924-
The child return code, set by :meth:`poll` and :meth:`wait` (and indirectly
925-
by :meth:`communicate`). A ``None`` value indicates that the process
926-
hasn't terminated yet.
924+
The child return code. Initially ``None``, :attr:`returncode` is set by
925+
a call to the :meth:`poll`, :meth:`wait`, or :meth:`communicate` methods
926+
if they detect that the process has terminated.
927+
928+
A ``None`` value indicates that the process hadn't yet terminated at the
929+
time of the last method call.
927930

928931
A negative value ``-N`` indicates that the child was terminated by signal
929932
``N`` (POSIX only).

Doc/library/types.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ Standard names are defined for the following types:
311311
.. versionchanged:: 3.9.2
312312
This type can now be subclassed.
313313

314+
.. seealso::
315+
316+
:ref:`Generic Alias Types<types-genericalias>`
317+
In-depth documentation on instances of :class:`!types.GenericAlias`
318+
319+
:pep:`585` - Type Hinting Generics In Standard Collections
320+
Introducing the :class:`!types.GenericAlias` class
314321

315322
.. class:: UnionType
316323

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_bdb.py

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

12111212

12121213
if __name__ == "__main__":

Lib/test/test_pdb.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,25 @@ def test_pdb_issue_gh_101673():
16531653
(Pdb) continue
16541654
"""
16551655

1656+
def test_pdb_issue_gh_101517():
1657+
"""See GH-101517
1658+
1659+
Make sure pdb doesn't crash when the exception is caught in a try/except* block
1660+
1661+
>>> def test_function():
1662+
... try:
1663+
... raise KeyError
1664+
... except* Exception as e:
1665+
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
1666+
1667+
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
1668+
... 'continue'
1669+
... ]):
1670+
... test_function()
1671+
> <doctest test.test_pdb.test_pdb_issue_gh_101517[0]>(4)test_function()
1672+
-> except* Exception as e:
1673+
(Pdb) continue
1674+
"""
16561675

16571676
@support.requires_subprocess()
16581677
class PdbTestCase(unittest.TestCase):
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: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3613,21 +3613,25 @@ compiler_try_except(struct compiler *c, stmt_ty s)
36133613
36143614
[orig, res, exc] <evaluate E1>
36153615
[orig, res, exc, E1] CHECK_EG_MATCH
3616-
[orig, red, rest/exc, match?] COPY 1
3617-
[orig, red, rest/exc, match?, match?] POP_JUMP_IF_NOT_NONE H1
3618-
[orig, red, exc, None] POP_TOP
3619-
[orig, red, exc] JUMP L2
3616+
[orig, res, rest/exc, match?] COPY 1
3617+
[orig, res, rest/exc, match?, match?] POP_JUMP_IF_NONE C1
36203618
3621-
[orig, res, rest, match] H1: <assign to V1> (or POP if no V1)
3619+
[orig, res, rest, match] <assign to V1> (or POP if no V1)
36223620
36233621
[orig, res, rest] SETUP_FINALLY R1
36243622
[orig, res, rest] <code for S1>
36253623
[orig, res, rest] JUMP L2
36263624
36273625
[orig, res, rest, i, v] R1: LIST_APPEND 3 ) exc raised in except* body - add to res
36283626
[orig, res, rest, i] POP
3627+
[orig, res, rest] JUMP LE2
36293628
3630-
[orig, res, rest] L2: <evaluate E2>
3629+
[orig, res, rest] L2: NOP ) for lineno
3630+
[orig, res, rest] JUMP LE2
3631+
3632+
[orig, res, rest/exc, None] C1: POP
3633+
3634+
[orig, res, rest] LE2: <evaluate E2>
36313635
.............................etc.......................
36323636
36333637
[orig, res, rest] Ln+1: LIST_APPEND 1 ) add unhandled exc to res (could be None)
@@ -3700,8 +3704,12 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
37003704
if (except == NULL) {
37013705
return 0;
37023706
}
3703-
basicblock *handle_match = compiler_new_block(c);
3704-
if (handle_match == NULL) {
3707+
basicblock *except_with_error = compiler_new_block(c);
3708+
if (except_with_error == NULL) {
3709+
return 0;
3710+
}
3711+
basicblock *no_match = compiler_new_block(c);
3712+
if (no_match == NULL) {
37053713
return 0;
37063714
}
37073715
if (i == 0) {
@@ -3725,13 +3733,9 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
37253733
VISIT(c, expr, handler->v.ExceptHandler.type);
37263734
ADDOP(c, CHECK_EG_MATCH);
37273735
ADDOP_I(c, COPY, 1);
3728-
ADDOP_JUMP(c, POP_JUMP_IF_NOT_NONE, handle_match);
3729-
ADDOP(c, POP_TOP); // match
3730-
ADDOP_JUMP(c, JUMP, except);
3736+
ADDOP_JUMP(c, POP_JUMP_IF_NONE, no_match);
37313737
}
37323738

3733-
compiler_use_next_block(c, handle_match);
3734-
37353739
basicblock *cleanup_end = compiler_new_block(c);
37363740
if (cleanup_end == NULL) {
37373741
return 0;
@@ -3793,8 +3797,14 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
37933797
ADDOP_I(c, LIST_APPEND, 3); // exc
37943798
ADDOP(c, POP_TOP); // lasti
37953799

3796-
ADDOP_JUMP(c, JUMP, except);
3800+
ADDOP_JUMP(c, JUMP, except_with_error);
37973801
compiler_use_next_block(c, except);
3802+
ADDOP(c, NOP); // to hold a propagated location info
3803+
ADDOP_JUMP(c, JUMP, except_with_error);
3804+
compiler_use_next_block(c, no_match);
3805+
ADDOP(c, POP_TOP); // match (None)
3806+
3807+
compiler_use_next_block(c, except_with_error);
37983808

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

0 commit comments

Comments
 (0)