Define properties as annotations for dynamic property group I'm trying to figure out how to generate a dynamic property group class, but I keep getting the annotations error: Warning: class PropBools contains a property which should be an annotation!. And following this error, I get the following printed line for each property: assign as a type annotation: PropBools.******.

Here is the code I have so far. I can show details about the list of data if it will help at all, but I don't think it will influence the error I'm getting.

PropBools = type(

        # typename
        'PropBools',

        # base class
        ( bpy.types.PropertyGroup , ),

        # dictionary of bool properties
        {
            ft.ID : bpy.props.BoolProperty(
                default         = False,
                name            = ft.Name,
                description     = ft.Desc,

                ) for ft in prop_list_data
        }
    )


Is it possible to do this without throwing the warning/error? Has anyone successfully generated a dynamic property group since the annotation requirement update?

Edit: I found Blender 2.8 - Field property declaration and dynamic class creation , which may be the only solution. Here is the same code, updated to define an annotations dictionary:

PropBools = type(

        # typename
        'PropBools',

        # base class
        ( bpy.types.PropertyGroup , ),

        # dictionary of bool properties
        {
            '__annotations__' :
            {
                ft.ID : ( BoolProperty,
                {
                    'default'       : False,
                    'name'          : ft.Name,
                    'description'   : ft.Desc

                } ) for ft in fuse.Type.Index
            }
        }
    )


You can even unpack dictionaries of extra parameters into it (this is a different dynamic class):

PropValues = type(

        # typename
        'PropValues',

        # base class
        ( bpy.types.PropertyGroup , ),

        # generate dictionary of override properties
        {
            '__annotations__' :
            {
                ft.ID : ( ft.Prop.Func,
                {
                    'default'       : ft.Default,
                    'name'          : ft.Name,
                    'description'   : ft.Desc,

                    # specify our property event function for updates
                    'update'        : ft.ValUpdate,

                    # unpack dictionary of keyword arguments to this property function
                    **ft.xop

                } ) for ft in fuse.Type.Index
            }
        }
    )


No warnings or errors using these yet, so seems promising.

Edit: This works great. The problems listed below were caused by an issue in the property list data, which was causing a silent error, which prevented ALL of the properties from registering, making the dynamic class appear empty. After finding and fixing the silent error, everything appears to be working.

However, the properties don't exist as they typically would in an instanced property group (of either dynamic class). Attempting to access a property using the syntax my_prop_group["id_name"] throws an error as if it doesn't exist. (A silent property error was causing this).

I'm not sure if I need to manually assign each one to default values (my_prop_group["id_name"] = DEFAULT).

Not sure if I need to include the entire dictionary of properties along with the __annotations__ dictionary of the same properties. Printing dir(*) of non-dynamic property groups seems to indicate that they should have both defined (silent error was causing properties to not register).
Hi your post is the closest to the issue that I'm having, and it seems like you've resolved your problem, I'm just not sure how the structure of your class can relate to the structure of the class in my problem that's throwing the error
I keep getting these annotation-type warnings which I understand are common but not breaking for addons that have compatibility 2.8 and 2.7, however, when trying to run blender in the background it becomes breaking.
Warning: class WM_OT_import_modal contains a property that should be an annotation!
c:\Users\Willard\Desktop\blender\2.82\scripts\addons\sketchfab_init_.py:1648
assign as a type annotation: WM_OT_import_modal.gltf_path
assign as a type annotation: WM_OT_import_modal.uid
You are using the latest version(1.3.1)
ERROR (wm.operator): c:\b\win64_cmake_vs2017\win64_cmake_vs2017\blender.git\source\blender\windowmanager\intern\wm_event_system.c:1486 wm_operator_invoke: invalid operator call ‘WM_OT_import_modal’

Below is the class in the addon throwing the error.
class ImportModalOperator(bpy.types.Operator):
    bl_idname = &quot;wm.import_modal&quot;
    bl_label = &quot;Import glTF model into Sketchfab&quot;ltf)
    bl_options = {'INTERNAL'}

    gltf_path = StringProperty()
    uid = StringProperty()

It would seem I just need to assign the properties: “gltf_path” and “uid” as type annotation to fix my error. But I can not conceive how to do this