Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nutti committed Oct 9, 2024
1 parent 84ab9a2 commit 0947d57
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
30 changes: 23 additions & 7 deletions src/fake_bpy_module/transformer/data_type_refiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,8 @@ def _get_refined_data_type_internal(
return []

def _parse_from_description(
self, module_name: str, description_str: str | None = None,
self, module_name: str, dtype_nodes: list[DataTypeNode],
description_str: str | None = None,
additional_info: dict[str, Any] | None = None
) -> tuple[list[DataTypeNode], bool]:

Expand All @@ -781,11 +782,26 @@ def _parse_from_description(

if REGEX_MATCH_DESCRIPTION_ENUMERATOR_IN.match(description_str) or \
REGEX_MATCH_DESCRIPTION_TYPE_IN.search(description_str):
enum_literal_type = get_rna_enum_name(description_str)
dtype_node = DataTypeNode()
append_child(dtype_node,
EnumRef(text=f"bpy.typing.{enum_literal_type}"))
return [dtype_node], True
is_set = False
for dtype_node in dtype_nodes:
if dtype_node.to_string() == "set":
is_set = True
break

if is_set:
enum_literal_type = get_rna_enum_name(description_str)
dtype_node = DataTypeNode()
append_child(dtype_node, nodes.Text("set["))
append_child(dtype_node,
EnumRef(text=f"bpy.typing.{enum_literal_type}"))
append_child(dtype_node, nodes.Text("]"))
return [dtype_node], True
else:

Check failure on line 799 in src/fake_bpy_module/transformer/data_type_refiner.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (RET505)

src/fake_bpy_module/transformer/data_type_refiner.py:799:13: RET505 Unnecessary `else` after `return` statement
enum_literal_type = get_rna_enum_name(description_str)
dtype_node = DataTypeNode()
append_child(dtype_node,
EnumRef(text=f"bpy.typing.{enum_literal_type}"))
return [dtype_node], True

return [], False

Expand All @@ -798,7 +814,7 @@ def refine(dtype_list_node: DataTypeListNode, module_name: str,

parsed_dtype_nodes, skip_parse_dtype_node = \
self._parse_from_description(
module_name, description_str=description_str,
module_name, dtype_nodes, description_str=description_str,
additional_info=additional_info)
new_dtype_nodes.extend(parsed_dtype_nodes)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def function_1(
arg_1: int,
arg_2: module_1.ClassA,
arg_3: bpy.typing.Enum1,
arg_4: bpy.typing.Enum1,
arg_4: set[bpy.typing.Enum1],
arg_5: bpy.typing.Enum1,
) -> module_1.submodule_1.BaseClass1:
"""function_1 description
Expand All @@ -22,7 +22,7 @@ def function_1(
:param arg_3: function_1 arg_3 description
:type arg_3: bpy.typing.Enum1
:param arg_4: Enumerator in `rna_enum_enum1`.
:type arg_4: bpy.typing.Enum1
:type arg_4: set[bpy.typing.Enum1]
:param arg_5: job type in `rna_enum_enum1`.
:type arg_5: bpy.typing.Enum1
:return: method_1 return description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def function_1(
arg_1: int,
arg_2: module_1.ClassA,
arg_3: bpy.typing.Enum1,
arg_4: bpy.typing.Enum1,
arg_4: set[bpy.typing.Enum1],
arg_5: bpy.typing.Enum1,
) -> module_1.submodule_1.BaseClass1:
"""function_1 description
Expand All @@ -21,7 +21,7 @@ def function_1(
:param arg_3: function_1 arg_3 description
:type arg_3: bpy.typing.Enum1
:param arg_4: Enumerator in `rna_enum_enum1`.
:type arg_4: bpy.typing.Enum1
:type arg_4: set[bpy.typing.Enum1]
:param arg_5: job type in `rna_enum_enum1`.
:type arg_5: bpy.typing.Enum1
:return: method_1 return description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
:arg arg_4: Enumerator in :ref:`rna_enum_enum1`.
:type arg_4: set
:arg arg_5: job type in :ref:`rna_enum_enum1`.
:type arg_5: set
:type arg_5: function_1 arg_5 type
:return: method_1 return description
:rtype: `module_1.submodule_1.BaseClass1`
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<default-value>
<data-type-list>
<data-type>
set
method_2 arg_2 type
<return>
<description>
<data-type-list>
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
<default-value>
<data-type-list>
<data-type>
set[
<enum-ref>
bpy.typing.Example
]
<argument argument_type="arg">
<name>
arg_2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
:arg arg_1: Enumerator in :ref:`rna_enum_example`.
:type arg_1: set
:arg arg_2: job type in :ref:`rna_enum_example`.
:type arg_2: set
:type arg_2: method_2 arg_2 type

0 comments on commit 0947d57

Please sign in to comment.