Supporting better Python-style runtime introspection in PyGObject

A bit over a week ago, I submitted a PR intended to expose function signatures in generated Python bindings here:

While the MR produces decent signatures including type information (including complex types like callbacks), I’ve left it as a draft since I think there are a few other changes needed to make this really useful.

The first was in this small MR that removes the “bound method” support code from PyGICallableInfo, and instead use the standard PyMethod_Type for this:

The main benefit of this is that the Python inspect module knows how to handle standard bound method objects, including how to derive their signature from the wrapped function object.

If we’re happy using standard method objects, one followup change would be to have MetaClassHelper wrap some PyGIFunctionInfo objects in staticmethod or classmethod objects where that would match their descriptor behaviour. This would help organise methods in pydoc output, and allow code that uses runtime introspection of the classes to guess how the methods behave on instances.

Eventually, it’d be nice if this was enough to feed into linters and other static analysis tools. I’d kind of hoped that mypy’s stubgen might be able to extract the signatures, but I’m not there yet.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.