mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
gh-111123: symtable should visit exception handlers before the else block (#111142)
This commit is contained in:
parent
f71cd5394e
commit
b578e51f02
4 changed files with 25 additions and 2 deletions
|
@ -106,6 +106,10 @@ Other Language Changes
|
||||||
the file is not accessible.
|
the file is not accessible.
|
||||||
(Contributed by Moonsik Park in :gh:`82367`.)
|
(Contributed by Moonsik Park in :gh:`82367`.)
|
||||||
|
|
||||||
|
* Fixed a bug where a :keyword:`global` decleration in an :keyword:`except` block
|
||||||
|
is rejected when the global is used in the :keyword:`else` block.
|
||||||
|
(Contributed by Irit Katriel in :gh:`111123`.)
|
||||||
|
|
||||||
New Modules
|
New Modules
|
||||||
===========
|
===========
|
||||||
|
|
||||||
|
|
|
@ -1283,6 +1283,23 @@ class TestSpecifics(unittest.TestCase):
|
||||||
def f():
|
def f():
|
||||||
a if (1 if b else c) else d
|
a if (1 if b else c) else d
|
||||||
|
|
||||||
|
def test_global_declaration_in_except_used_in_else(self):
|
||||||
|
# See gh-111123
|
||||||
|
code = textwrap.dedent("""\
|
||||||
|
def f():
|
||||||
|
try:
|
||||||
|
pass
|
||||||
|
%s Exception:
|
||||||
|
global a
|
||||||
|
else:
|
||||||
|
print(a)
|
||||||
|
""")
|
||||||
|
|
||||||
|
g, l = {'a': 5}, {}
|
||||||
|
for kw in ("except", "except*"):
|
||||||
|
exec(code % kw, g, l);
|
||||||
|
|
||||||
|
|
||||||
@requires_debug_ranges()
|
@requires_debug_ranges()
|
||||||
class TestSourcePositions(unittest.TestCase):
|
class TestSourcePositions(unittest.TestCase):
|
||||||
# Ensure that compiled code snippets have correct line and column numbers
|
# Ensure that compiled code snippets have correct line and column numbers
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix a bug where a :keyword:`global` declaration in an :keyword:`except` block
|
||||||
|
is rejected when the global is used in the :keyword:`else` block.
|
|
@ -1813,14 +1813,14 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
|
||||||
break;
|
break;
|
||||||
case Try_kind:
|
case Try_kind:
|
||||||
VISIT_SEQ(st, stmt, s->v.Try.body);
|
VISIT_SEQ(st, stmt, s->v.Try.body);
|
||||||
VISIT_SEQ(st, stmt, s->v.Try.orelse);
|
|
||||||
VISIT_SEQ(st, excepthandler, s->v.Try.handlers);
|
VISIT_SEQ(st, excepthandler, s->v.Try.handlers);
|
||||||
|
VISIT_SEQ(st, stmt, s->v.Try.orelse);
|
||||||
VISIT_SEQ(st, stmt, s->v.Try.finalbody);
|
VISIT_SEQ(st, stmt, s->v.Try.finalbody);
|
||||||
break;
|
break;
|
||||||
case TryStar_kind:
|
case TryStar_kind:
|
||||||
VISIT_SEQ(st, stmt, s->v.TryStar.body);
|
VISIT_SEQ(st, stmt, s->v.TryStar.body);
|
||||||
VISIT_SEQ(st, stmt, s->v.TryStar.orelse);
|
|
||||||
VISIT_SEQ(st, excepthandler, s->v.TryStar.handlers);
|
VISIT_SEQ(st, excepthandler, s->v.TryStar.handlers);
|
||||||
|
VISIT_SEQ(st, stmt, s->v.TryStar.orelse);
|
||||||
VISIT_SEQ(st, stmt, s->v.TryStar.finalbody);
|
VISIT_SEQ(st, stmt, s->v.TryStar.finalbody);
|
||||||
break;
|
break;
|
||||||
case Assert_kind:
|
case Assert_kind:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue