Skip to content

Commit

Permalink
Update: Support parsing 'BMLayerCollection of' data type (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
nutti committed Oct 10, 2024
1 parent 09e4782 commit 8056613
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 26 deletions.
23 changes: 19 additions & 4 deletions src/fake_bpy_module/transformer/data_type_refiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
REGEX_MATCH_DATA_TYPE_LIST_OF_PARENTHESES_VALUE = re.compile(r"^list of \(([a-zA-Z.,` ]+)\)") # noqa: E501
REGEX_MATCH_DATA_TYPE_PAIR_OF_VALUE = re.compile(r"^pair of `([A-Za-z0-9_.]+)`")
REGEX_MATCH_DATA_TYPE_BMELEMSEQ_OF_VALUE = re.compile(r"`BMElemSeq` of `([a-zA-Z0-9]+)`$") # noqa: E501
REGEX_MATCH_DATA_TYPE_BMLAYERCOLLECTION_OF_VALUE = re.compile(r"`BMLayerCollection` of ([a-zA-Z0-9_]+)$") # noqa: E501
REGEX_MATCH_DATA_TYPE_BMLAYERCOLLECTION_OF_CLASS = re.compile(r"`BMLayerCollection` of `([a-zA-Z0-9._]+)`$") # noqa: E501
REGEX_MATCH_DATA_TYPE_TUPLE_OF_VALUE = re.compile(r"^tuple of `([a-zA-Z0-9.]+)`('s)*$") # noqa: E501
REGEX_MATCH_DATA_TYPE_LIST_OR_DICT_OR_SET_OR_TUPLE = re.compile(r"^`*(list|dict|set|tuple)`*\.*$") # noqa: E501
REGEX_MATCH_DATA_TYPE_OT = re.compile(r"^`([A-Z]+)_OT_([A-Za-z_]+)`$")
Expand Down Expand Up @@ -165,7 +167,7 @@ def _parse_custom_data_type(

return None

# pylint: disable=R0911,R0912,R0913
# pylint: disable=R0911,R0912,R0913,R0915
def _get_refined_data_type_fast( # noqa: C901, PLR0911, PLR0912
self, dtype_str: str, uniq_full_names: set[str],
uniq_module_names: set[str], module_name: str,
Expand Down Expand Up @@ -468,9 +470,22 @@ def _get_refined_data_type_fast( # noqa: C901, PLR0911, PLR0912
s = self._parse_custom_data_type(
m.group(1), uniq_full_names, uniq_module_names, module_name)
if s:
return [
make_data_type_node(f"`bmesh.types.BMElemSeq`[`{s}`]")
]
return [make_data_type_node(f"`bmesh.types.BMElemSeq`[`{s}`]")]
# [Ex] BMLayerCollection of float
if m := REGEX_MATCH_DATA_TYPE_BMLAYERCOLLECTION_OF_VALUE.match(
dtype_str):
return [make_data_type_node(
f"`bmesh.types.BMLayerCollection`[{m.group(1)}]"
)]
# [Ex] BMLayerCollection of `mathutils.Vector`
if m := REGEX_MATCH_DATA_TYPE_BMLAYERCOLLECTION_OF_CLASS.match(
dtype_str):
s = self._parse_custom_data_type(
m.group(1), uniq_full_names, uniq_module_names, module_name)
if s:
return [make_data_type_node(
f"`bmesh.types.BMLayerCollection`[`{s}`]"
)]
# [Ex] tuple of mathutils.Vector's
if m := REGEX_MATCH_DATA_TYPE_TUPLE_OF_VALUE.match(dtype_str):
s = self._parse_custom_data_type(
Expand Down
53 changes: 31 additions & 22 deletions src/mods/common/analyzer/append/bmesh.types.mod.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,93 +129,102 @@

.. class:: BMLayerCollection

:generic-types: _GenericType2
:generic-types: _GenericType1

.. method:: get()

:rtype: :class:`BMLayerItem` | _GenericType2
:rtype: :class:`BMLayerItem`\ [_GenericType1] | _GenericType2
:mod-option rtype: skip-refine
:generic-types: _GenericType2

.. class:: BMVert

:generic-types: _GenericType1

.. method:: __getitem__(key)

:type key: :class:`BMLayerItem`
:type key: :class:`BMLayerItem`\ [_GenericType1]
:mod-option arg key: skip-refine
:rtype: typing.Any
:rtype: _GenericType1
:mod-option rtype: skip-refine

.. method:: __setitem__(key, value)

:type key: :class:`BMLayerItem`
:type key: :class:`BMLayerItem`\ [_GenericType1]
:mod-option arg key: skip-refine
:type value: typing.Any
:type value: _GenericType1
:mod-option arg value: skip-refine

.. method:: __delitem__(key)

:type key: :class:`BMLayerItem`
:type key: :class:`BMLayerItem`\ [_GenericType1]
:mod-option arg key: skip-refine

.. class:: BMEdge

:generic-types: _GenericType1

.. method:: __getitem__(key)

:type key: :class:`BMLayerItem`
:type key: :class:`BMLayerItem`\ [_GenericType1]
:mod-option arg key: skip-refine
:rtype: typing.Any
:rtype: _GenericType1
:mod-option rtype: skip-refine

.. method:: __setitem__(key, value)

:type key: :class:`BMLayerItem`
:type key: :class:`BMLayerItem`\ [_GenericType1]
:mod-option arg key: skip-refine
:type value: typing.Any
:type value: _GenericType1
:mod-option arg value: skip-refine

.. method:: __delitem__(key)

:type key: :class:`BMLayerItem`
:type key: :class:`BMLayerItem`\ [_GenericType1]
:mod-option arg key: skip-refine

.. class:: BMFace

:generic-types: _GenericType1

.. method:: __getitem__(key)

:type key: :class:`BMLayerItem`
:type key: :class:`BMLayerItem`\ [_GenericType1]
:mod-option arg key: skip-refine
:rtype: typing.Any
:rtype: _GenericType1
:mod-option rtype: skip-refine

.. method:: __setitem__(key, value)

:type key: :class:`BMLayerItem`
:type key: :class:`BMLayerItem`\ [_GenericType1]
:mod-option arg key: skip-refine
:type value: typing.Any
:type value: _GenericType1
:mod-option arg value: skip-refine

.. method:: __delitem__(key)

:type key: :class:`BMLayerItem`
:type key: :class:`BMLayerItem`\ [_GenericType1]
:mod-option arg key: skip-refine

.. class:: BMLoop

:generic-types: _GenericType1

.. method:: __getitem__(key)

:type key: :class:`BMLayerItem`
:type key: :class:`BMLayerItem`\ [_GenericType1]
:mod-option arg key: skip-refine
:rtype: typing.Any
:rtype: _GenericType1
:mod-option rtype: skip-refine

.. method:: __setitem__(key, value)

:type key: :class:`BMLayerItem`
:type key: :class:`BMLayerItem`\ [_GenericType1]
:mod-option arg key: skip-refine
:type value: typing.Any
:type value: _GenericType1
:mod-option arg value: skip-refine

.. method:: __delitem__(key)

:type key: :class:`BMLayerItem`
:type key: :class:`BMLayerItem`\ [_GenericType1]
:mod-option arg key: skip-refine
34 changes: 34 additions & 0 deletions src/mods/common/analyzer/update/bmesh.types.mod.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,46 @@

.. class:: BMLayerCollection

.. attribute:: active

:type: :class:`bmesh.types.BMLayerItem`\ [_GenericType1]
:mod-option attribute: skip-refine

.. method:: get(key, default=None)

:type default: _GenericType2
:mod-option arg default: skip-refine
:generic-types: _GenericType2

.. method:: items()

:rtype: list[str, :class:`bmesh.types.BMLayerItem`\ [_GenericType1]]
:mod-option rtype: skip-refine

.. method:: new()

:rtype: :class:`bmesh.types.BMLayerItem`\ [_GenericType1]
:mod-option rtype: skip-refine

.. method:: remove(layer)

:type layer: :class:`bmesh.types.BMLayerItem`\ [_GenericType1]
:mod-option arg layer: skip-refine

.. method:: values()

:rtype: list[:class:`bmesh.types.BMLayerItem`\ [_GenericType1]]
:mod-option rtype: skip-refine

.. method:: verify()

:rtype: :class:`bmesh.types.BMLayerItem`\ [_GenericType1]
:mod-option rtype: skip-refine

.. class:: BMLayerItem

:generic-types: _GenericType1

.. class:: BMVert

.. method:: copy_from(other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,26 @@
of
<class-ref>
RefinedClassA
<data>
<name>
data_bmlayercollection_of_value
<description>
<data-type-list>
<data-type>
<class-ref>
BMLayerCollection
of float
<data>
<name>
data_bmlayercollection_of_class
<description>
<data-type-list>
<data-type>
<class-ref>
BMLayerCollection
of
<class-ref>
ClassA
<data>
<name>
data_tuple_of_value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,27 @@
<class-ref>
refined_module_a.RefinedClassA
]
<data>
<name>
data_bmlayercollection_of_value
<description>
<data-type-list>
<data-type option="never none">
<class-ref>
bmesh.types.BMLayerCollection
[float]
<data>
<name>
data_bmlayercollection_of_class
<description>
<data-type-list>
<data-type option="never none">
<class-ref>
bmesh.types.BMLayerCollection
[
<class-ref>
module_1.ClassA
]
<data>
<name>
data_tuple_of_value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@

:type: :class:`BMElemSeq` of :class:`RefinedClassA`

.. data:: data_bmlayercollection_of_value

:type: :class:`BMLayerCollection` of float

.. data:: data_bmlayercollection_of_class

:type: :class:`BMLayerCollection` of :class:`ClassA`

.. data:: data_tuple_of_value

:type: tuple of :class:`RefinedClassA`'s
Expand Down

0 comments on commit 8056613

Please sign in to comment.