From 3477b4adf702da7f99bd90e45d6c3561ef287f0e Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sat, 4 May 2024 11:02:51 +0200 Subject: [PATCH] fix: Include lines of examples that start with `...` (#130) Closes #129 ### Summary of Changes Lines of examples that start with `...` are now included in the generated stubs. --- src/safeds_stubgen/stubs_generator/_generate_stubs.py | 2 ++ tests/data/docstring_parser_package/numpydoc.py | 8 ++++++-- ...est_stub_docstring_creation[numpydoc-NUMPYDOC].sdsstub | 8 ++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 706be944..a54cc362 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -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" diff --git a/tests/data/docstring_parser_package/numpydoc.py b/tests/data/docstring_parser_package/numpydoc.py index c965301c..80de1262 100644 --- a/tests/data/docstring_parser_package/numpydoc.py +++ b/tests/data/docstring_parser_package/numpydoc.py @@ -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. """ @@ -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. """ diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/test_stub_docstring_creation[numpydoc-NUMPYDOC].sdsstub b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/test_stub_docstring_creation[numpydoc-NUMPYDOC].sdsstub index 35943ec0..755cdd3c 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/test_stub_docstring_creation[numpydoc-NUMPYDOC].sdsstub +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/test_stub_docstring_creation[numpydoc-NUMPYDOC].sdsstub @@ -411,7 +411,9 @@ class ClassWithVariousAttributeTypes() { * @example * pipeline example { * // from tests.data.docstring_parser_package.numpydoc import NumpyClassWithExamples - * // class_ = NumpyClassWithExamples + * // class_ = ( + * // NumpyClassWithExamples + * // ) * } */ class NumpyClassWithExamples() { @@ -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() * } */