Skip to content

Commit

Permalink
Print type in freeze_type() error messages
Browse files Browse the repository at this point in the history
Summary:
Might make debugging errors like
https://fb.workplace.com/groups/cinderusers/posts/3563718873774137/ easier in
the future.

Reviewed By: brittanyrey, DinoV

Differential Revision: D63906345

fbshipit-source-id: fa6be37a6f6b2fd39fd8544ba48fcea55f6f1c40
  • Loading branch information
Alex Malyshev authored and facebook-github-bot committed Oct 7, 2024
1 parent bc0d99f commit 0a169e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Lib/test/test_cinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class D:
del D.foo

def test_type_freeze_bad_arg(self):
with self.assertRaisesRegex(TypeError, "freeze_type requires a type"):
with self.assertRaisesRegex(TypeError, "freeze_type requires a type, got int"):
cinder.freeze_type(42)

def test_cached_class_prop(self):
Expand Down
12 changes: 8 additions & 4 deletions Modules/_cinder.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ static PyObject *
cinder_freeze_type(PyObject *self, PyObject *o)
{
if (!PyType_Check(o)) {
PyErr_SetString(
PyErr_Format(
PyExc_TypeError,
"freeze_type requires a type");
"freeze_type requires a type, got %s",
Py_TYPE(o)->tp_name
);
return NULL;
}
((PyTypeObject*)o)->tp_flags |= Ci_Py_TPFLAGS_FROZEN;
Expand All @@ -109,9 +111,11 @@ static PyObject *
cinder_warn_on_inst_dict(PyObject *self, PyObject *o)
{
if (!PyType_Check(o)) {
PyErr_SetString(
PyErr_Format(
PyExc_TypeError,
"warn_on_inst_dict requires a type");
"warn_on_inst_dict requires a type, got %s",
Py_TYPE(o)->tp_name
);
return NULL;
} else if (((PyTypeObject *)o)->tp_flags & Ci_Py_TPFLAGS_FROZEN) {
PyErr_SetString(
Expand Down

0 comments on commit 0a169e2

Please sign in to comment.