libdrgn: python: add documentation and type annotation for Program.__contains__()

drgn.Program has supported the "in" operator since commit 25e7a9d3b8
("libdrgn/python: implement Program.__contains__"), but it's
undocumented and unannotated. Add a type annotation with a docstring
along with a METH_COEXIST method.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
This commit is contained in:
Omar Sandoval 2021-05-12 16:19:42 -07:00
parent 179b33c76f
commit ad37c79cba
2 changed files with 11 additions and 2 deletions

View File

@ -105,7 +105,15 @@ class Program:
>>> prog['jiffies']
Object(prog, 'volatile unsigned long', address=0xffffffff94c05000)
:param name: The object name.
:param name: Object name.
"""
...
def __contains__(self, name: str) -> bool:
"""
Implement ``name in self``. Return whether an object (variable,
constant, or function) with the given name exists in the program.
:param name: Object name.
"""
...
def variable(self, name: str, filename: Optional[str] = None) -> Object:

View File

@ -879,6 +879,8 @@ static PyMethodDef Program_methods[] = {
drgn_Program_load_default_debug_info_DOC},
{"__getitem__", (PyCFunction)Program_subscript, METH_O | METH_COEXIST,
drgn_Program___getitem___DOC},
{"__contains__", (PyCFunction)Program_contains, METH_O | METH_COEXIST,
drgn_Program___contains___DOC},
{"read", (PyCFunction)Program_read, METH_VARARGS | METH_KEYWORDS,
drgn_Program_read_DOC},
#define METHOD_DEF_READ(x) \
@ -950,7 +952,6 @@ static PyMappingMethods Program_as_mapping = {
.mp_subscript = (binaryfunc)Program_subscript,
};
static PySequenceMethods Program_as_sequence = {
.sq_contains = (objobjproc)Program_contains,
};