Skip to content

Commit

Permalink
fix: Include lines of examples that start with ... (#130)
Browse files Browse the repository at this point in the history
Closes #129

### Summary of Changes

Lines of examples that start with `...` are now included in the
generated stubs.
  • Loading branch information
lars-reimann authored May 4, 2024
1 parent b4493c9 commit 3477b4a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/safeds_stubgen/stubs_generator/_generate_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,8 @@ def _create_sds_docstring(
for example_part in docstring.example.split("\n"):
if example_part.startswith(">>>"):
example += f"{indentations} * {example_part.replace('>>>', '//')}\n"
elif example_part.startswith("..."):
example += f"{indentations} * {example_part.replace('...', '//')}\n"
example += f"{indentations} * }}\n"
if full_docstring and example:
full_docstring += f"{indentations} *\n"
Expand Down
8 changes: 6 additions & 2 deletions tests/data/docstring_parser_package/numpydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ class NumpyClassWithExamples:
--------
>>> from tests.data.docstring_parser_package.numpydoc import NumpyClassWithExamples
This text should be ignored
>>> class_ = NumpyClassWithExamples
>>> class_ = (
... NumpyClassWithExamples
... )
This text should be ignored, too.
"""

Expand All @@ -497,7 +499,9 @@ def numpy_func_with_examples(self):
Examples
--------
>>> from tests.data.docstring_parser_package.numpydoc import NumpyClassWithExamples
>>> func = NumpyClassWithExamples.numpy_func_with_examples
>>> func = (
... NumpyClassWithExamples.numpy_func_with_examples
... )
>>> func()
This text should be ignored.
"""
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ class ClassWithVariousAttributeTypes() {
* @example
* pipeline example {
* // from tests.data.docstring_parser_package.numpydoc import NumpyClassWithExamples
* // class_ = NumpyClassWithExamples
* // class_ = (
* // NumpyClassWithExamples
* // )
* }
*/
class NumpyClassWithExamples() {
Expand All @@ -420,7 +422,9 @@ class NumpyClassWithExamples() {
* @example
* pipeline example {
* // from tests.data.docstring_parser_package.numpydoc import NumpyClassWithExamples
* // func = NumpyClassWithExamples.numpy_func_with_examples
* // func = (
* // NumpyClassWithExamples.numpy_func_with_examples
* // )
* // func()
* }
*/
Expand Down

0 comments on commit 3477b4a

Please sign in to comment.