GNOME Bugzilla – Bug 564070
Cannot use GOptionGroup raw wrappers with glib.option.OptionParser
Last modified: 2018-01-10 19:58:04 UTC
$ python -c "import gobject, gstoption; a = gobject.option.OptionParser(); a.add_option_group(gstoption.get_group()); a.parse_args()" Traceback (most recent call last):
+ Trace 210683
for key, value in group.values.__dict__.items():
It seems adding a glib option group (as opposed to a purely Python OptParse group) causes an attribute error when parsing args.
Created attachment 128697 [details] [review] Remove the offending code; as far as i can tell the parsing works perfectly without it.
What is gstoption? Can you provide an example without additional dependencies?
Gstoption is the goption group for GStreamer's python bindings. The GOption system in python uses two types of groups internally. Any options which are defined in Python will create a optparse group. Any GOption which is defined in C code will be of the type glib.OptionGroup. The python bindings for GOption allow both these types of groups to be used simultaneously, and it works fine with optparse groups. However it fails with this error for glib.OptionGroup types. Since anything created in Python will be an optparse group, I believe you must use a C module such as gstoption to create a glib.OptionGroup type. Therefore I do not know if it is possible to create an example without an extra dependency, but I will investigate this.
I have a gst-python application that has several command line options, so I've come across this issue as well. (In reply to comment #2) > What is gstoption? Can you provide an example without additional dependencies? Laszlo's example generalizes to any glib.OptionGroup (of which gstoption.get_group() returns an instance). So the following example produces an almost identical traceback: $ python -c "import gobject, glib; a = gobject.option.OptionParser();a.add_option_group(glib.OptionGroup('foo', 'bar', 'bat', None)); a.parse_args()" Traceback (most recent call last):
+ Trace 223318
Has Laszlo's patch been tested? Does it work?
Review of attachment 128697 [details] [review]: ::: glib/option.py @@ -343,3 @@ - for group in self.option_groups: - for key, value in group.values.__dict__.items(): - options.ensure_value(key, value) Removing this breaks support for glib.option.OptionGroup. This loop merges the values of each group into options. Instead of removing it, a guard may be added to support GOptionGroup raw wrappers.
Created attachment 212495 [details] Test case This bug is still applies with latest pygobject. As it used deprecated optparse module, we should move to argparse as well.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/2.