mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-23 09:43:06 +00:00
libdrgn/python: make Object.__index__() TypeError message clearer
Currently, we print: >>> prog.symbol(prog['init_task']) Traceback (most recent call last): File "<console>", line 1, in <module> TypeError: cannot convert 'struct task_struct' to index It's not obvious what it means to convert to an index. Instead, let's use the error message raised by operator.index(): TypeError: 'struct task_struct' object cannot be interpreted as an integer
This commit is contained in:
parent
4adc691622
commit
9de2cc8410
@ -1264,7 +1264,7 @@ static PyObject *DrgnObject_index(DrgnObject *self)
|
|||||||
underlying_type = drgn_underlying_type(self->obj.type);
|
underlying_type = drgn_underlying_type(self->obj.type);
|
||||||
if (!drgn_type_is_integer(underlying_type) &&
|
if (!drgn_type_is_integer(underlying_type) &&
|
||||||
drgn_type_kind(underlying_type) != DRGN_TYPE_POINTER) {
|
drgn_type_kind(underlying_type) != DRGN_TYPE_POINTER) {
|
||||||
return set_error_type_name("cannot convert '%s' to index",
|
return set_error_type_name("'%s' object cannot be interpreted as an integer",
|
||||||
drgn_object_qualified_type(&self->obj));
|
drgn_object_qualified_type(&self->obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,13 +701,13 @@ class TestConversions(ObjectTestCase):
|
|||||||
|
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
TypeError,
|
TypeError,
|
||||||
"cannot convert 'double' to index",
|
"'double' object cannot be interpreted as an integer",
|
||||||
operator.index,
|
operator.index,
|
||||||
Object(self.prog, "double", value=9.99),
|
Object(self.prog, "double", value=9.99),
|
||||||
)
|
)
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
TypeError,
|
TypeError,
|
||||||
r"cannot convert 'int \[\]' to index",
|
r"'int \[\]' object cannot be interpreted as an integer",
|
||||||
operator.index,
|
operator.index,
|
||||||
Object(self.prog, "int []", address=0),
|
Object(self.prog, "int []", address=0),
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user