the file is not accessible.
(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
===========
def f():
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()
class TestSourcePositions(unittest.TestCase):
# Ensure that compiled code snippets have correct line and column numbers
break;
case Try_kind:
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, stmt, s->v.Try.orelse);
VISIT_SEQ(st, stmt, s->v.Try.finalbody);
break;
case TryStar_kind:
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, stmt, s->v.TryStar.orelse);
VISIT_SEQ(st, stmt, s->v.TryStar.finalbody);
break;
case Assert_kind: