Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nutti committed Sep 21, 2024
1 parent e96377a commit e6908fa
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/fake_bpy_module/analyzer/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def run(self) -> list[ClassNode]:
for field in field_list:
fname_node, fbody_node = field.children
if fname_node.astext() == "generic-types":
class_node.attributes["generic-types"] = fbody_node.astext()
class_node.attributes[fname_node.astext()] = fbody_node.astext()

Check failure on line 354 in src/fake_bpy_module/analyzer/directives.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

src/fake_bpy_module/analyzer/directives.py:354:81: E501 Line too long (84 > 80)

return [class_node]

Expand Down Expand Up @@ -495,7 +495,8 @@ def _parse_signature_detail(self, func_node: FunctionNode,
elif m.group(2) == "function":
func_node.attributes[m.group(1)] = fbody_node.astext()
elif fname_node.astext() == "generic-types":
func_node.attributes["generic-types"] = fbody_node.astext()
func_node.attributes[fname_node.astext()] = \
fbody_node.astext()

def run(self) -> list[FunctionNode]:
paragraph: nodes.paragraph = nodes.paragraph()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,16 @@ def test_option(self) -> None:
self.assertEqual(len(documents), len(rst_files))
for doc, expect in zip(documents, expect_files, strict=True):
self.compare_with_file_contents(doc.pformat(), expect)

def test_generic_types(self) -> None:
rst_files = ["generic_types.rst"]
expect_files = ["generic_types.xml"]
rst_files = [f"{self.data_dir}/input/{f}" for f in rst_files]
expect_files = [f"{self.data_dir}/expect/{f}" for f in expect_files]

analyzer = BaseAnalyzer()
documents = analyzer.analyze(rst_files)

self.assertEqual(len(documents), len(rst_files))
for doc, expect in zip(documents, expect_files, strict=True):
self.compare_with_file_contents(doc.pformat(), expect)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<document source="<string>">
<source-filename>
option.rst
<module>
<name>
module_1
<description>
<class generic_types="_GenericType1">
<name>
ClassA
<description>
<base-class-list>
<attribute-list>
<function-list>
<function function_type="method" generic_types="_GenericType2" option="overload">
<name>
method_1
<description>
<argument-list>
<argument argument_type="arg">
<name>
arg_1
<description>
<default-value>
<data-type-list>
<data-type>
_GenericType1
<argument argument_type="arg">
<name>
arg_2
<description>
<default-value>
<data-type-list>
<data-type>
_GenericType2
<return>
<description>
<data-type-list>
<function function_type="method" generic_types="_GenericType1" option="overload">
<name>
method_1
<description>
<argument-list>
<argument argument_type="arg">
<name>
arg_1
<description>
<default-value>
<data-type-list>
<data-type>
_GenericType1
<return>
<description>
<data-type-list>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. module:: module_1

.. class:: ClassA

:generic-types: _GenericType1

.. method:: method_1(arg_1, arg_2)

:type arg_1: _GenericType1
:type arg_2: _GenericType2
:generic-types: _GenericType2

.. function:: method_1(arg_1)

:type arg_1: _GenericType1
:generic-types: _GenericType1

0 comments on commit e6908fa

Please sign in to comment.