Skip to content

Commit

Permalink
Use ValueError instead of RuntimeError
Browse files Browse the repository at this point in the history
  • Loading branch information
gaogaotiantian committed Oct 18, 2024
1 parent c8a8eb4 commit d16cfad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Lib/test/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,16 @@ def test_delete(self):
with self.assertRaises(KeyError):
d.pop('non_exist')

with self.assertRaisesRegex(RuntimeError, 'local variables'):
with self.assertRaisesRegex(ValueError, 'local variables'):
del d['x']

with self.assertRaises(AttributeError):
d.clear()

with self.assertRaises(RuntimeError):
with self.assertRaises(ValueError):
d.pop('x')

with self.assertRaises(RuntimeError):
with self.assertRaises(ValueError):
d.pop('x', None)

# 'm', 'n' is stored in f_extra_locals
Expand Down
4 changes: 2 additions & 2 deletions Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ framelocalsproxy_setitem(PyObject *self, PyObject *key, PyObject *value)
}
if (i >= 0) {
if (value == NULL) {
PyErr_SetString(PyExc_RuntimeError, "cannot remove local variables from FrameLocalsProxy");
PyErr_SetString(PyExc_ValueError, "cannot remove local variables from FrameLocalsProxy");
return -1;
}

Expand Down Expand Up @@ -707,7 +707,7 @@ framelocalsproxy_pop(PyObject* self, PyObject *const *args, Py_ssize_t nargs)
}

if (i >= 0) {
PyErr_SetString(PyExc_RuntimeError, "cannot remove local variables from FrameLocalsProxy");
PyErr_SetString(PyExc_ValueError, "cannot remove local variables from FrameLocalsProxy");
return NULL;
}

Expand Down

0 comments on commit d16cfad

Please sign in to comment.