From 9bac66a01baae521338e0b6845f6ce63aebad854 Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Sat, 3 Jan 2026 17:53:59 +0000 Subject: [PATCH] Fix for python 3.14 "In some versions of Python, instances of classes may have an __annotations__ attribute. However, this is not supported functionality. If you need the annotations of an instance, you can use type() to access its class" https://docs.python.org/3/howto/annotations.html --- src/bonsai/bonsai/bim/helper.py | 6 +++++- src/bonsai/bonsai/tool/blender.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bonsai/bonsai/bim/helper.py b/src/bonsai/bonsai/bim/helper.py index 3b3dd502e4..e76b512de3 100644 --- a/src/bonsai/bonsai/bim/helper.py +++ b/src/bonsai/bonsai/bim/helper.py @@ -428,7 +428,11 @@ def get_enum_items( else: annotations_data = data - prop = annotations_data.__annotations__[prop_name] + try: + annotations = annotations_data.__annotations__ + except AttributeError: + annotations = type(annotations_data).__annotations__ + prop = annotations[prop_name] items = prop.keywords.get("items") if items is None: return diff --git a/src/bonsai/bonsai/tool/blender.py b/src/bonsai/bonsai/tool/blender.py index 97b161a11b..09bfcf29cc 100644 --- a/src/bonsai/bonsai/tool/blender.py +++ b/src/bonsai/bonsai/tool/blender.py @@ -742,7 +742,11 @@ class Blender(bonsai.core.tool.Blender): # Yes, accessing items through annotations is a bit hacky # but it's the only way to get the dynamic enum items # besides providing them to get_enum_safe explicitly. - prop_keywords = props.__annotations__[prop_name].keywords + try: + annotations = props.__annotations__ + except AttributeError: + annotations = type(props).__annotations__ + prop_keywords = annotations[prop_name].keywords items = prop_keywords.get("items") if items is None: return None