Skip to content

Commit

Permalink
fix: Result names for multiple results from docstrings (#155)
Browse files Browse the repository at this point in the history
Closes #138

### Summary of Changes

If number of results and docstrings types correspond then docstring
names are taken for the results.
  • Loading branch information
Masara authored Jun 18, 2024
1 parent 187d6df commit ebcadbb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/safeds_stubgen/api_analyzer/_ast_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,19 @@ def _parse_results(
name=f"{result_name}",
),
]
elif len(return_results) == len(result_docstrings):
zipped = zip(return_results, result_docstrings, strict=True)

for type_, result_docstring in zipped:
result_name = result_docstring.name or next(name_generator)

all_results.append(
Result(
id=f"{function_id}/{result_name}",
type=type_,
name=f"{result_name}",
),
)
else:
for type_ in return_results:
result_docstring = ResultDocstring()
Expand Down
12 changes: 12 additions & 0 deletions tests/data/docstring_parser_package/numpydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,15 @@ def numpy_named_result_without_type_inferred():
this will be the return value
"""
return "result"


def numpy_named_result_with_more_hints_than_docstring_types() -> tuple[int, str]:
"""
numpy_named_result_without_type_inferred
Returns
-------
named_result : int
this will be the return value
"""
...
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ fun numpyNamedResultWithoutType() -> namedResult: String
@PythonName("numpy_named_result_without_type_inferred")
fun numpyNamedResultWithoutTypeInferred() -> namedResult: String

/**
* numpy_named_result_without_type_inferred
*
* @result namedResult this will be the return value
*/
@Pure
@PythonName("numpy_named_result_with_more_hints_than_docstring_types")
fun numpyNamedResultWithMoreHintsThanDocstringTypes() -> (namedResult: Int, result1: String)

/**
* ClassWithDocumentation. Code::
*
Expand Down

0 comments on commit ebcadbb

Please sign in to comment.