Python 3: How do obtain and compare GObject.GTypes from GIMP classes?

I’m writing GIMP 2.99 python plugins. All of the arguments in a Gimp Procedure are held as an array of GParamSpec instances. I want to assert that each argument value is the type I expect. My problem is that the type information is a GType and it is unclear how to use that in Python to compare types.
For example, I want to know that arg[0] is a “Gimp.RunMode”

def assert_layers_procedure(procedure):
    #  An array of GParamSpec
    procedure_args_raw = procedure.get_arguments()
    # The first GParamSpec
    arg_zero_raw = procedure_args_raw[0]
    # Apparently, arg_zero_type is a "GType GimpRunMode (4194814752)"
    arg_zero_type = arg_zero_raw.value_type  # type: GObject.GType
    if arg_zero_type is not Gimp.RunMode: # Yes, I know this is wrong. What should it be?
        raise TypeError('procedure %s argument %d is not the correct type Gimp.RunMode, instead, it is type %s.'
                        % (proc_name, 0, arg_zero_type))

The TypeError is always raised, because “GType GimpRunMode” is not Gimp.RunMode, nor anything I have guessed at. I don’t know how to obtain a GType of a GIMP class, nor compare GTypes (assuming GType.is_a()) in Python 3.0.
What might work?
Thanks in advance!

I don’t have deep knowledge of the implementation specifics of gobject introspection as done through pygobject. You could look at the tests for gtype there.

Note that for the GImpImageProcedure case at least, RunMode, Image and Drawables are already tested to be of the correct type by GIMP. You may only need to check if it is the type of drawable that you are expecting (layer, channel, …).

In Python, you can directly use the builtin function isinstance:

isinstance(arg_zero_raw, Gimp.RunMode)

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