gh-118331: Handle errors in _PyObject_SetManagedDict (#118334)

When detaching a dict, the `copy_values` call may fail due to
out-of-memory errors. This can be triggered by test_no_memory in
test_repl.
3 files changed