Skip to content

Commit

Permalink
Init: Annotations util func
Browse files Browse the repository at this point in the history
  • Loading branch information
loonaticx committed Oct 15, 2023
1 parent 7a14541 commit 46cd9db
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,23 @@ def menu_func(self, context):
self.layout.operator(IMPORT_OT_egg.bl_idname, text = "Panda3D (.egg)")


def make_annotations(cls):
"""Converts class fields to annotations if running with Blender 2.8"""
if bpy.app.version < (2, 80):
return cls
bl_props = {k: v for k, v in cls.__dict__.items() if isinstance(v, tuple)}
if bl_props:
if '__annotations__' not in cls.__dict__:
setattr(cls, '__annotations__', {})
annotations = cls.__dict__['__annotations__']
for k, v in bl_props.items():
annotations[k] = v
delattr(cls, k)
return cls


def register():
make_annotations(IMPORT_OT_egg)
bpy.utils.register_class(IMPORT_OT_egg)

if bpy.app.version >= (2, 80):
Expand Down

0 comments on commit 46cd9db

Please sign in to comment.