pygobject / pygobject-stubs

PEP 561 Typing Stubs for PyGObject
GNU Lesser General Public License v2.1
74 stars 26 forks source link

Support GLib.option (or use a better placeholder) #148

Open cebtenzzre opened 1 year ago

cebtenzzre commented 1 year ago

Here is a simple example:

from gi.repository import GLib

parser = GLib.option.OptionParser(option_list=[
    GLib.option.make_option('--flag', action='store_true', help='flag'),
])
parser.parse_args()
print('flag is', parser.values.flag)

mypy complains about type errors:

$ mypy repr.py
repr.py:3: error: "ellipsis" has no attribute "OptionParser"  [attr-defined]
repr.py:4: error: "ellipsis" has no attribute "make_option"  [attr-defined]
Found 2 errors in 1 file (checked 1 source file)

It looks like the placeholder for this attribute is currently a literal ellipsis: https://github.com/pygobject/pygobject-stubs/blob/97a1be6bdd843d1eb0bfe617e3f8e635592335e2/src/gi-stubs/repository/GLib.pyi#L206

I believe stubgen annotates attributes with _typeshed.Incomplete when the type cannot be determined. typing.Any would probably work as well.

lovetox commented 1 year ago

When was this added? I find no documentation online for this.

lovetox commented 1 year ago

Seems its this module here https://gitlab.gnome.org/GNOME/pygobject/-/blob/master/gi/_option.py