Re: docstrings, module help, and default arguments




Hi,

On Sat, Feb 2, 2013 at 4:54 AM, Niklas Koep <niklas koep gmail com> wrote:
Hey,

I have a couple of questions regarding gobject-introspection but with a direct focus on pygobject. Instead of cluttering the mailing list with multiple mails I thought I'd just post one. I hope that was alright.

I was under the impression that one of the many benefits of gobject-introspection was that in the case of generating dynamic python bindings we would also get automatically generated docstrings for functions, classes and methods based on annotations resp. gtk-docs. From my own tests, as well as from inspecting the dynamic bindings for gtk or gstreamer, it seems this is not the case though. Is this the intended behaviour?

This unfortunately isn't the case. The docs are stored in intermediate .gir files (xml) but pygobject uses binary .typelib files for bindings, which do not contain docs AFAICT. The best we can do at the moment is adding function signatures to doc strings. For example:

help(Gst.init)
init(*args, **kwargs)
    init(argc:int, argv:list) -> argc:int, argv:list

This example also points out issues with dynamic bindings and dynamic docs in that the logic for how arguments are handled needs to be duplicated in both code paths. The docs above are wrong because the argc argument is automatically handled by pygobject using the list length. Luckily this is a strait forward and there are a limited number of these problems.
There is the possibility having a tool like pydoc or even setting pyobject into a mode in which it could interact with g-ir-doc-tool or its libraries. So things like pydoc/epydoc would just work. This could layer the work being done for general gi documentation with python specifics (argument coercion and overrides docs). But researching this more than just having the thought is a fairly low priority for me at the moment. Help is needed. See:
https://bugzilla.gnome.org/show_bug.cgi?id=625494
and
https://live.gnome.org/GObjectIntrospection/Doctools

Another issue I'm having is that functions defined in my module namespace won't show up in the help for my module, e.g. 

    python2 -c "from gi.repository import MyModule; help(MyModule)" 

doesn't list any of my implemented functions. They are properly annotated in the C-code as they are listed in the gir file and I can call them just fine from python. I noticed a similar behaviour for gstreamer functions. Functions listed in the Gst-1.0.gir file are callable from python, but not listed in the module's help text. Introspected classes, however, appear in the help text. Why is that?

This looks like it might be a bug with how the dynamic introspection module is appearing to pydoc. Please log it here: https://bugzilla.gnome.org/enter_bug.cgi?product=pygobject

Another thing I was wondering about is if default arguments for functions and methods are supported yet. Again, a gstreamer example: I've seen lots of code snippets like

    playbin = Gst.ElementFactory.make("playbin2")

on the net, even though according to the C documentation gst_element_factory_make requires you to pass two arguments to the function: the element you want to create and a unique name. The name argument is annotated with allow-none, but I still have to pass None as second argument if I call the method from python as otherwise a TypeError exception is raised. This is what I would consider correct behaviour, but I'm still wondering if all the code examples are simply erroneous or if I'm overlooking something.

Optional arguments are currently not supported because there is no way to get defaults from the introspection API. See: https://bugzilla.gnome.org/show_bug.cgi?id=558620

-Simon


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]