Python 3: How do I assert that the value of a gobject.GParamSpec is of a particular type?

26 Views Asked by At

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 everything is either wrapped, and/or mapped, and sparsely documented for Python. (In this case, as a GType). So simple uses of python 3.0's instanceOf() and "is" operator can't do what I want. 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]
    arg_zero_type = arg_zero_raw.value_type
    # Apparently, arg_zero_type is a "GType GimpRunMode (4194814752)"
    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 Gimp.RunMode.__gtype__, or anything I have guessed at. I don't know how to compare arg_zero_type to the type of classes like Gimp.RunMode in Python 3.0 What might work?

0

There are 0 best solutions below