[Bf-blender-cvs] [3789ab4166c] master: PyAPI: fix rna_info for changes in type access

Campbell Barton noreply at git.blender.org
Mon Sep 4 08:32:30 CEST 2017


Commit: 3789ab4166c40d254ab1cf9f07d429730650efdb
Author: Campbell Barton
Date:   Mon Sep 4 16:39:13 2017 +1000
Branches: master
https://developer.blender.org/rB3789ab4166c40d254ab1cf9f07d429730650efdb

PyAPI: fix rna_info for changes in type access

===================================================================

M	release/scripts/modules/rna_info.py

===================================================================

diff --git a/release/scripts/modules/rna_info.py b/release/scripts/modules/rna_info.py
index 94f5e9e17bb..03f43486371 100644
--- a/release/scripts/modules/rna_info.py
+++ b/release/scripts/modules/rna_info.py
@@ -82,6 +82,32 @@ def float_as_string(f):
     return val_str
 
 
+def get_py_class_from_rna(rna_type):
+    """ Get's the Python type for a class which isn't necessarily added to ``bpy.types``.
+    """
+    identifier = rna_type.identifier
+    py_class = getattr(bpy.types, identifier, None)
+    if py_class is not None:
+        return py_class
+
+    def subclasses_recurse(cls):
+        for c in cls.__subclasses__():
+            # is_registered
+            if "bl_rna" in cls.__dict__:
+                yield c
+            yield from subclasses_recurse(c)
+
+    while py_class is None:
+        base = rna_type.base
+        if base is None:
+            raise Exception("can't find type")
+        py_class_base = getattr(bpy.types, base.identifier, None)
+        if py_class_base is not None:
+            for cls in subclasses_recurse(py_class_base):
+                if cls.bl_rna.identifier == identifier:
+                    return cls
+
+
 class InfoStructRNA:
     __slots__ = (
         "bl_rna",
@@ -146,7 +172,8 @@ class InfoStructRNA:
 
     def _get_py_visible_attrs(self):
         attrs = []
-        py_class = getattr(bpy.types, self.identifier)
+        py_class = get_py_class_from_rna(self.bl_rna)
+
         for attr_str in dir(py_class):
             if attr_str.startswith("_"):
                 continue
@@ -437,7 +464,11 @@ class InfoOperatorRNA:
             self.args.append(prop)
 
     def get_location(self):
-        op_class = getattr(bpy.types, self.identifier)
+        try:
+            op_class = getattr(bpy.types, self.identifier)
+        except AttributeError:
+            # defined in C.
+            return None, None
         op_func = getattr(op_class, "execute", None)
         if op_func is None:
             op_func = getattr(op_class, "invoke", None)



More information about the Bf-blender-cvs mailing list