Skip to content

Commit

Permalink
Fix: Missing __len__ in bpy_prop_collection and Matrix class (nutti#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
nutti committed Nov 8, 2022
1 parent d05f524 commit 6e04eab
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/fake_bpy_module/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import copy

from .common import (
BuiltinDataType,
CustomDataType,
DataType,
IntermidiateDataType,
Expand Down Expand Up @@ -1391,7 +1392,7 @@ def _add_getitem_and_setitem(self, class_info: 'ClassInfo', dtype: str):
info.set_module(class_info.module())
class_info.add_method(info)

def _add_iter_and_next(self, class_info: 'ClassInfo', dtype: str):
def _add_iter_next_len(self, class_info: 'ClassInfo', dtype: str):
info = FunctionInfo("method")
info.set_name("__iter__")
info.set_parameters([])
Expand All @@ -1418,6 +1419,18 @@ def _add_iter_and_next(self, class_info: 'ClassInfo', dtype: str):
info.set_return(return_info)
class_info.add_method(info)

info = FunctionInfo("method")
info.set_name("__len__")
info.set_parameters([])
info.set_parameter_details([])
info.set_class(class_info.name())
info.set_module(class_info.module())
return_info = ReturnInfo()
return_info.set_description("")
return_info.set_data_type(BuiltinDataType("int"))
info.set_return(return_info)
class_info.add_method(info)

def _tweak_bpy_types_classes(self, result: 'AnalysisResult'):
for section in result.section_info:
for info in section.info_list:
Expand All @@ -1432,7 +1445,7 @@ def _tweak_bpy_types_classes(self, result: 'AnalysisResult'):
# def __setitem__(self, key: Union[str, int],
# value: GenericType):
self._add_getitem_and_setitem(info, "GenericType")
self._add_iter_and_next(info, "GenericType")
self._add_iter_next_len(info, "GenericType")
info.add_base_class(
CustomDataType(
"GenericType", ModifierDataType("Generic"),
Expand Down
11 changes: 11 additions & 0 deletions src/mods/common/analyzer/mathutils.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@
"data_type": ""
}
},
{
"name": "__len__",
"type": "method",
"module": "mathutils",
"parameters": [],
"parameter_details": [],
"return": {
"type": "return",
"data_type": "int"
}
},
{
"name": "__add__",
"type": "method",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,20 @@ def test_tweak_bpy_types_classes(self):
"data_type": "'GenericType'",
"description": ""
}
},
{
"type": "method",
"name": "__len__",
"description": "",
"class": "bpy_prop_collection",
"module": "bpy.types",
"parameters": [],
"parameter_details": [],
"return": {
"type": "return",
"data_type": "int",
"description": ""
}
}
]
}, method='NEW')
Expand Down

0 comments on commit 6e04eab

Please sign in to comment.