diff --git a/src/fake_bpy_module/common.py b/src/fake_bpy_module/common.py index e8b885949..8e68ceb61 100644 --- a/src/fake_bpy_module/common.py +++ b/src/fake_bpy_module/common.py @@ -32,6 +32,7 @@ MODIFIER_DATA_TYPE: List[str] = [ "list", "dict", "set", "tuple", + "iteriter", "listlist", "tupletuple", "listtuple", "listcallable", "Generic", @@ -288,6 +289,8 @@ def to_string(self) -> str: return f"typing.Tuple[{', '.join(inner_str)}]" elif self._modifier.modifier_data_type() == "listlist": return f"typing.List[typing.List[{self._data_type}]]" + elif self._modifier.modifier_data_type() == "iteriter": + return f"typing.Iterable[typing.Iterable[{self._data_type}]]" elif self._modifier.modifier_data_type() == 'listtuple': if self._modifier_add_info is not None: return "typing.List[typing.Tuple[" \ @@ -382,6 +385,8 @@ def to_string(self) -> str: f"{', '.join(elms_strs)}]" elif self._modifier.modifier_data_type() == "listlist": return f"typing.List[typing.List['{self._data_type}']]" + elif self._modifier.modifier_data_type() == "iteriter": + return f"typing.Iterable[typing.Iterable['{self._data_type}']]" elif self._modifier.modifier_data_type() == "listcallable": return "typing.List[typing.Callable[['" \ f"{','.join(self._modifier_add_info['arguments'])}'], None]]" @@ -1592,14 +1597,15 @@ def _get_refined_data_type_fast( if m: return BuiltinDataType("str", ModifierDataType("set")) - # Ex: sequence of string tuples or a function + # [Pattern] sequence of string tuples or a function + # [Test] + # File: refiner_test.py + # Function: test_get_refined_data_type_for_various_patterns + # Pattern: sequence of string tuples or a function m = re.match(r"^sequence of string tuples or a function$", dtype_str) if m: dtypes = [ - BuiltinDataType("int", ModifierDataType("listtuple"), - modifier_add_info={ - "tuple_elms": ["str", "str", "str"] - }), + BuiltinDataType("str", ModifierDataType("iteriter")), ModifierDataType("typing.Callable") ] return MixinDataType(dtypes) diff --git a/tests/python/fake_bpy_module_test/fake_bpy_module_test/refiner_test.py b/tests/python/fake_bpy_module_test/fake_bpy_module_test/refiner_test.py index 85ebefcc3..3eeb1cdc4 100644 --- a/tests/python/fake_bpy_module_test/fake_bpy_module_test/refiner_test.py +++ b/tests/python/fake_bpy_module_test/fake_bpy_module_test/refiner_test.py @@ -613,3 +613,17 @@ def test_get_refined_data_type_for_various_patterns(self): self.assertFalse(refined_data_type.has_modifier()) self.assertEqual( refined_data_type.to_string(), "'module.ClassB'") + + # Pattern: sequence of string tuples or a function + # Ref: https://github.com/nutti/fake-bpy-module/issues/140 + intermidiate_data_type = IntermidiateDataType( + "sequence of string tuples or a function") + refined_data_type = refiner.get_refined_data_type( + intermidiate_data_type, "module_1", 'FUNC_ARG') + self.assertEqual(refined_data_type.type(), 'BUILTIN') + self.assertEqual(refined_data_type.data_type(), "str") + self.assertTrue(refined_data_type.has_modifier()) + self.assertEqual(refined_data_type.modifier().modifier_data_type(), + "iteriter") + self.assertEqual(refined_data_type.to_string(), + "typing.Iterable[typing.Iterable[str]]")