Skip to content

Commit 061eb21

Browse files
committed
KeyError when syncing from mapping should be ignored; fixed unit test
1 parent 1137510 commit 061eb21

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Lib/test/test_builtin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,7 @@ def func_assign():
11171117

11181118
def func_read():
11191119
b = a + 1
1120+
a = 3
11201121

11211122
for executor in eval, exec:
11221123
with self.subTest(executor=executor.__name__):
@@ -1125,8 +1126,8 @@ def func_read():
11251126
self.assertEqual(ns, {'a': 1})
11261127
ns = {'a': 1}
11271128
executor(func_read.__code__, {}, ns, sync_fast_locals=True)
1128-
self.assertEqual(ns, {'a': 1, 'b': 2})
1129-
1129+
self.assertEqual(ns, {'a': 3, 'b': 2})
1130+
11301131
def test_filter(self):
11311132
self.assertEqual(list(filter(lambda c: 'a' <= c <= 'z', 'Hello World')), list('elloorld'))
11321133
self.assertEqual(list(filter(None, [1, 'hello', [], [3], '', None, 9, 0])), [1, 'hello', [3], 9])

Python/ceval.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,9 @@ _PyEval_SyncLocalsToFast(_PyInterpreterFrame *frame)
15421542
if (value != NULL) {
15431543
frame->localsplus[i] = PyStackRef_FromPyObjectSteal(value);
15441544
}
1545+
else if (PyErr_ExceptionMatches(PyExc_KeyError)) {
1546+
PyErr_Clear();
1547+
}
15451548
else {
15461549
return -1;
15471550
}

0 commit comments

Comments
 (0)