From 684a101ca5369bc2aff0e8c76804b0c3e533f60a Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Sat, 30 Mar 2024 14:26:44 +0100 Subject: [PATCH] fix: Removed the Epydoc parser (#89) ### Summary of Changes I removed everything concerning the epydoc parser. --------- Co-authored-by: Lars Reimann --- .../docstring_parsing/__init__.py | 2 - .../_create_docstring_parser.py | 5 +- .../docstring_parsing/_docstring_style.py | 1 - .../docstring_parsing/_epydoc_parser.py | 123 -------- .../stubs_generator/_generate_stubs.py | 5 +- tests/data/docstring_parser_package/epydoc.py | 159 ---------- .../docstring_module.py | 30 -- .../__snapshots__/test__get_api.ambr | 191 ----------- .../api_analyzer/test__get_api.py | 21 -- .../docstring_parsing/test_docstring_style.py | 1 - .../docstring_parsing/test_epydoc_parser.py | 297 ------------------ ...st_stub_creation[docstring_module].sdsstub | 32 -- ..._docstring_creation[epydoc-EPYDOC].sdsstub | 153 --------- .../stubs_generator/test_generate_stubs.py | 1 - 14 files changed, 2 insertions(+), 1019 deletions(-) delete mode 100644 src/safeds_stubgen/docstring_parsing/_epydoc_parser.py delete mode 100644 tests/data/docstring_parser_package/epydoc.py delete mode 100644 tests/safeds_stubgen/docstring_parsing/test_epydoc_parser.py delete mode 100644 tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/test_stub_docstring_creation[epydoc-EPYDOC].sdsstub diff --git a/src/safeds_stubgen/docstring_parsing/__init__.py b/src/safeds_stubgen/docstring_parsing/__init__.py index d1099ce4..638555ff 100644 --- a/src/safeds_stubgen/docstring_parsing/__init__.py +++ b/src/safeds_stubgen/docstring_parsing/__init__.py @@ -4,7 +4,6 @@ from ._create_docstring_parser import create_docstring_parser from ._docstring import AttributeDocstring, ClassDocstring, FunctionDocstring, ParameterDocstring, ResultDocstring from ._docstring_style import DocstringStyle -from ._epydoc_parser import EpydocParser from ._googledoc_parser import GoogleDocParser from ._numpydoc_parser import NumpyDocParser from ._plaintext_docstring_parser import PlaintextDocstringParser @@ -16,7 +15,6 @@ "ClassDocstring", "create_docstring_parser", "DocstringStyle", - "EpydocParser", "FunctionDocstring", "GoogleDocParser", "NumpyDocParser", diff --git a/src/safeds_stubgen/docstring_parsing/_create_docstring_parser.py b/src/safeds_stubgen/docstring_parsing/_create_docstring_parser.py index 7ac188c9..0769060c 100644 --- a/src/safeds_stubgen/docstring_parsing/_create_docstring_parser.py +++ b/src/safeds_stubgen/docstring_parsing/_create_docstring_parser.py @@ -3,7 +3,6 @@ from typing import TYPE_CHECKING from ._docstring_style import DocstringStyle -from ._epydoc_parser import EpydocParser from ._googledoc_parser import GoogleDocParser from ._numpydoc_parser import NumpyDocParser from ._plaintext_docstring_parser import PlaintextDocstringParser @@ -14,9 +13,7 @@ def create_docstring_parser(style: DocstringStyle) -> AbstractDocstringParser: - if style == DocstringStyle.EPYDOC: - return EpydocParser() - elif style == DocstringStyle.GOOGLE: + if style == DocstringStyle.GOOGLE: return GoogleDocParser() elif style == DocstringStyle.NUMPYDOC: return NumpyDocParser() diff --git a/src/safeds_stubgen/docstring_parsing/_docstring_style.py b/src/safeds_stubgen/docstring_parsing/_docstring_style.py index e7116892..a531c972 100644 --- a/src/safeds_stubgen/docstring_parsing/_docstring_style.py +++ b/src/safeds_stubgen/docstring_parsing/_docstring_style.py @@ -6,7 +6,6 @@ class DocstringStyle(Enum): # AUTO = "auto", PLAINTEXT = "plaintext" - EPYDOC = "epydoc" GOOGLE = "google" NUMPYDOC = "numpydoc" REST = "rest" diff --git a/src/safeds_stubgen/docstring_parsing/_epydoc_parser.py b/src/safeds_stubgen/docstring_parsing/_epydoc_parser.py deleted file mode 100644 index b111712a..00000000 --- a/src/safeds_stubgen/docstring_parsing/_epydoc_parser.py +++ /dev/null @@ -1,123 +0,0 @@ -from __future__ import annotations - -from typing import TYPE_CHECKING - -from docstring_parser import Docstring, DocstringParam -from docstring_parser import DocstringStyle as DP_DocstringStyle -from docstring_parser import parse as parse_docstring - -from ._abstract_docstring_parser import AbstractDocstringParser -from ._docstring import ( - AttributeDocstring, - ClassDocstring, - FunctionDocstring, - ParameterDocstring, - ResultDocstring, -) -from ._helpers import get_description, get_full_docstring - -if TYPE_CHECKING: - from mypy import nodes - - from safeds_stubgen.api_analyzer import Class, ParameterAssignment - - -class EpydocParser(AbstractDocstringParser): - """Parses documentation in the Epydoc format. - - See https://epydoc.sourceforge.net/epytext.html for more information. - This class is not thread-safe. Each thread should create its own instance. - """ - - def __init__(self) -> None: - self.__cached_node: nodes.FuncDef | None = None - self.__cached_docstring: Docstring | None = None - - def get_class_documentation(self, class_node: nodes.ClassDef) -> ClassDocstring: - docstring = get_full_docstring(class_node) - docstring_obj = parse_docstring(docstring, style=DP_DocstringStyle.EPYDOC) - - return ClassDocstring( - description=get_description(docstring_obj), - full_docstring=docstring, - ) - - def get_function_documentation(self, function_node: nodes.FuncDef) -> FunctionDocstring: - docstring = get_full_docstring(function_node) - docstring_obj = self.__get_cached_epydoc_string(function_node, docstring) - - return FunctionDocstring( - description=get_description(docstring_obj), - full_docstring=docstring, - ) - - def get_parameter_documentation( - self, - function_node: nodes.FuncDef, - parameter_name: str, - parameter_assigned_by: ParameterAssignment, # noqa: ARG002 - parent_class: Class | None, - ) -> ParameterDocstring: - from safeds_stubgen.api_analyzer import Class - - # For constructors (__init__ functions) the parameters are described on the class - if function_node.name == "__init__" and isinstance(parent_class, Class): - docstring = parent_class.docstring.full_docstring - else: - docstring = get_full_docstring(function_node) - - # Find matching parameter docstrings - function_epydoc = self.__get_cached_epydoc_string(function_node, docstring) - all_parameters_epydoc: list[DocstringParam] = function_epydoc.params - matching_parameters_epydoc = [it for it in all_parameters_epydoc if it.arg_name == parameter_name] - - if len(matching_parameters_epydoc) == 0: - return ParameterDocstring() - - last_parameter_docstring_obj = matching_parameters_epydoc[-1] - return ParameterDocstring( - type=last_parameter_docstring_obj.type_name or "", - default_value=last_parameter_docstring_obj.default or "", - description=last_parameter_docstring_obj.description or "", - ) - - # Todo Epydoc: Attribute handling not yet implemented in docstring_parser library - def get_attribute_documentation( - self, - parent_class: Class, # noqa: ARG002 - attribute_name: str, # noqa: ARG002 - ) -> AttributeDocstring: - return AttributeDocstring() - - def get_result_documentation(self, function_node: nodes.FuncDef) -> ResultDocstring: - docstring = get_full_docstring(function_node) - - # Find matching parameter docstrings - function_epydoc = self.__get_cached_epydoc_string(function_node, docstring) - function_returns = function_epydoc.returns - - if function_returns is None: - return ResultDocstring() - - return ResultDocstring( - type=function_returns.type_name or "", - description=function_returns.description or "", - ) - - def __get_cached_epydoc_string(self, node: nodes.FuncDef, docstring: str) -> Docstring: - """ - Return the EpydocString for the given function node. - - It is only recomputed when the function node differs from the previous one that was passed to this function. - This avoids reparsing the docstring for the function itself and all of its parameters. - - On Lars's system this caused a significant performance improvement: Previously, 8.382s were spent inside the - function get_parameter_documentation when parsing sklearn. Afterwards, it was only 2.113s. - """ - if self.__cached_node is not node or node.name == "__init__": - self.__cached_node = node - self.__cached_docstring = parse_docstring(docstring, style=DP_DocstringStyle.EPYDOC) - - if self.__cached_docstring is None: # pragma: no cover - raise ValueError("Expected a docstring, got None instead.") - return self.__cached_docstring diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 42bc478d..8bc0b422 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -693,7 +693,7 @@ def _create_type_string(self, type_data: dict | None) -> str: case _: self._add_to_imports(type_data["qname"]) - # inner classes that are private should not be used as types, therefore we add a todo + # inner classes that are private should not be used as types, therefore we add a TODO if name[0] == "_" and type_data["qname"] not in self.module_imports: self._current_todo_msgs.add("internal class as type") @@ -937,9 +937,6 @@ def _module_name_check(name: str, string: str) -> bool: if shortest_id is None or len(fixed_module_id_parts) < len(shortest_id): shortest_id = fixed_module_id_parts - if len(shortest_id) == 1: - break - if shortest_id is None: return module_qname return ".".join(shortest_id) diff --git a/tests/data/docstring_parser_package/epydoc.py b/tests/data/docstring_parser_package/epydoc.py deleted file mode 100644 index b1b834ed..00000000 --- a/tests/data/docstring_parser_package/epydoc.py +++ /dev/null @@ -1,159 +0,0 @@ -""" -Test module for docstring tests. - -A module for testing the various docstring types. -""" -from enum import Enum - - -class ClassWithDocumentation: - """ - Lorem ipsum. Code:: - - pass - - Dolor sit amet. - """ - - -class ClassWithoutDocumentation: - pass - - -def function_with_documentation() -> None: - """ - Lorem ipsum. Code:: - - pass - - Dolor sit amet. - """ - - -def function_without_documentation() -> None: - pass - - -class ClassWithParameters: - """ - Lorem ipsum. - - Dolor sit amet. - - @param p: foo defaults to 1 - @type p: int - """ - - def __init__(self, p) -> None: - pass - - -class ClassWithAttributes: - """ - Lorem ipsum. - - Dolor sit amet. - - @ivar p: foo defaults to 1 - @type p: int - @ivar q: foo defaults to 1 - @type q: int - """ - p: int - q = 1 - - def __init__(self) -> None: - pass - - -class ClassWithAttributesNoType: - """ - Lorem ipsum. - - Dolor sit amet. - - @ivar p: foo defaults to 1 - @ivar q: foo defaults to 1 - """ - p: int - q = 1 - - def __init__(self) -> None: - pass - - -def function_with_parameters(no_type_no_default, type_no_default, with_default, *args, **kwargs) -> None: - """ - Lorem ipsum. - - Dolor sit amet. - - @param no_type_no_default: no type and no default - @param type_no_default: type but no default - @type type_no_default: int - @param with_default: foo that defaults to 2 - @type with_default: int - """ - - -def function_with_result_value_and_type() -> bool: - """ - Lorem ipsum. - - Dolor sit amet. - - @return: return value - @rtype: bool - """ - - -def function_with_result_value_no_type() -> None: - """ - Lorem ipsum. - - Dolor sit amet. - - @return: return value - """ - - -def function_without_result_value(): - """ - Lorem ipsum. - - Dolor sit amet. - """ - - -class ClassWithMethod: - def method_with_docstring(self, a) -> bool: - """ - Lorem ipsum. - - Dolor sit amet. - - @param a: type but no default - @type a: int - - @return: return value - @rtype: bool - """ - - @property - def property_method_with_docstring(self) -> bool: - """ - Lorem ipsum. - - Dolor sit amet. - - @return: return value - @rtype: bool - """ - - -class EnumDocstring(Enum): - """ - Lorem ipsum. - - Dolor sit amet. - """ diff --git a/tests/data/various_modules_package/docstring_module.py b/tests/data/various_modules_package/docstring_module.py index a5313d6e..6990aa77 100644 --- a/tests/data/various_modules_package/docstring_module.py +++ b/tests/data/various_modules_package/docstring_module.py @@ -4,36 +4,6 @@ """ -class EpydocDocstringClass: - """ - A class with a variety of different methods for calculations. (Epydoc). - - @ivar attr_1: Attribute of the calculator. (Epydoc) - @type attr_1: str - @param param_1: Parameter of the calculator. (Epydoc) - @type param_1: str - """ - - attr_1: str - - def __init__(self, param_1: str): - pass - - def epydoc_docstring_func(self, x: int, y: int) -> bool: - """ - This function checks if the sum of x and y is less than the value 10 and returns True if it is. (Epydoc). - - @param x: First integer value for the calculation. (Epydoc) - @type x: int - @param y: Second integer value for the calculation. (Epydoc) - @type y: int - @return: Checks if the sum of x and y is greater than 10. (Epydoc) - @rtype: bool - """ - z = x + y - return z < 10 - - class RestDocstringClass: """ A class with a variety of different methods for calculations. (ReST). diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 59b97ce0..41c136a5 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -1378,41 +1378,6 @@ }), ]) # --- -# name: test_class_methods[EpydocDocstringClass] - list([ - dict({ - 'docstring': dict({ - 'description': 'This function checks if the sum of x and y is less than the value 10 and returns True if it is. (Epydoc).', - 'full_docstring': ''' - This function checks if the sum of x and y is less than the value 10 and returns True if it is. (Epydoc). - - @param x: First integer value for the calculation. (Epydoc) - @type x: int - @param y: Second integer value for the calculation. (Epydoc) - @type y: int - @return: Checks if the sum of x and y is greater than 10. (Epydoc) - @rtype: bool - ''', - }), - 'id': 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', - 'is_class_method': False, - 'is_property': False, - 'is_public': True, - 'is_static': False, - 'name': 'epydoc_docstring_func', - 'parameters': list([ - 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', - 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', - 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', - ]), - }), - ]) -# --- # name: test_class_methods[FunctionModuleClassB] list([ dict({ @@ -2245,59 +2210,6 @@ ]), }) # --- -# name: test_classes[EpydocDocstringClass] - dict({ - 'attributes': list([ - 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/attr_1', - ]), - 'classes': list([ - ]), - 'constructor': dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/__init__', - 'is_class_method': False, - 'is_property': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/__init__/self', - 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/__init__/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - 'docstring': dict({ - 'description': 'A class with a variety of different methods for calculations. (Epydoc).', - 'full_docstring': ''' - A class with a variety of different methods for calculations. (Epydoc). - - @ivar attr_1: Attribute of the calculator. (Epydoc) - @type attr_1: str - @param param_1: Parameter of the calculator. (Epydoc) - @type param_1: str - ''', - }), - 'id': 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass', - 'inherits_from_exception': False, - 'is_public': True, - 'methods': list([ - 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', - ]), - 'name': 'EpydocDocstringClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'type_parameters': list([ - ]), - }) -# --- # name: test_classes[FourthReexportClass] dict({ 'attributes': list([ @@ -3274,91 +3186,6 @@ }), ]) # --- -# name: test_function_parameters[epydoc.__init__] - list([ - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': 'Parameter of the calculator. (Epydoc)', - 'type': 'str', - }), - 'id': 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/__init__/param_1', - 'is_optional': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/__init__/self', - 'is_optional': False, - 'name': 'self', - 'type': None, - }), - ]) -# --- -# name: test_function_parameters[epydoc_docstring_func] - list([ - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', - 'is_optional': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': 'First integer value for the calculation. (Epydoc)', - 'type': 'int', - }), - 'id': 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', - 'is_optional': False, - 'name': 'x', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': 'Second integer value for the calculation. (Epydoc)', - 'type': 'int', - }), - 'id': 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', - 'is_optional': False, - 'name': 'y', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - }), - ]) -# --- # name: test_function_parameters[google.__init__] list([ dict({ @@ -4919,23 +4746,6 @@ }), ]) # --- -# name: test_function_results[epydoc_docstring_func] - list([ - dict({ - 'docstring': dict({ - 'description': 'Checks if the sum of x and y is greater than 10. (Epydoc)', - 'type': 'bool', - }), - 'id': 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - 'qname': 'builtins.bool', - }), - }), - ]) -# --- # name: test_function_results[float_result] list([ dict({ @@ -6980,7 +6790,6 @@ # name: test_modules[docstring_module] dict({ 'classes': list([ - 'tests/data/various_modules_package/docstring_module/EpydocDocstringClass', 'tests/data/various_modules_package/docstring_module/RestDocstringClass', 'tests/data/various_modules_package/docstring_module/NumpyDocstringClass', 'tests/data/various_modules_package/docstring_module/GoogleDocstringClass', diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index e98c9605..d91b4fab 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -23,13 +23,6 @@ is_test_run=True, ).to_dict() -api_data_epydoc = get_api( - package_name=_test_package_name, - root=package_root, - docstring_style=DocstringStyle.EPYDOC, - is_test_run=True, -).to_dict() - api_data_numpy = get_api( package_name=_test_package_name, root=package_root, @@ -79,7 +72,6 @@ def _get_specific_class_data( def get_api_data(docstring_style: str) -> dict: return { "plaintext": api_data_paintext, - "epydoc": api_data_epydoc, "numpydoc": api_data_numpy, "rest": api_data_rest, "google": api_data_google, @@ -188,7 +180,6 @@ def test_imports(module_name: str, import_type: str, snapshot: SnapshotAssertion ("variance_module", "VarianceClassOnlyContravarianceNoBound", "plaintext"), ("variance_module", "VarianceClassAll", "plaintext"), (_infer_types_module_name, "InferMyTypes", "plaintext"), - (_docstring_module_name, "EpydocDocstringClass", "epydoc"), (_docstring_module_name, "RestDocstringClass", "rest"), (_docstring_module_name, "NumpyDocstringClass", "numpydoc"), (_docstring_module_name, "GoogleDocstringClass", "google"), @@ -211,7 +202,6 @@ def test_imports(module_name: str, import_type: str, snapshot: SnapshotAssertion "VarianceClassOnlyContravarianceNoBound", "VarianceClassAll", "InferMyTypes", - "EpydocDocstringClass", "RestDocstringClass", "NumpyDocstringClass", "GoogleDocstringClass", @@ -227,14 +217,12 @@ def test_classes(module_name: str, class_name: str, docstring_style: str, snapsh assert class_data == snapshot -# Todo Epydoc Tests are deactivated right now, since attribute handling is not implemented yet for the docstring_parser @pytest.mark.parametrize( argnames=("module_name", "class_name", "docstring_style"), argvalues=[ ("attribute_module", "AttributesClassB", "plaintext"), (_class_module_name, "ClassModuleNestedClassE", "plaintext"), (_class_module_name, "_ClassModulePrivateClassG", "plaintext"), - # (_docstring_module_name, "EpydocDocstringClass", "epydoc"), (_docstring_module_name, "RestDocstringClass", "rest"), (_docstring_module_name, "NumpyDocstringClass", "numpydoc"), (_docstring_module_name, "GoogleDocstringClass", "google"), @@ -243,7 +231,6 @@ def test_classes(module_name: str, class_name: str, docstring_style: str, snapsh "AttributesClassB", "ClassModuleNestedClassE", "_ClassModulePrivateClassG", - # "EpydocDocstringClass", "RestDocstringClass", "NumpyDocstringClass", "GoogleDocstringClass", @@ -359,7 +346,6 @@ def test_global_functions(module_name: str, snapshot: SnapshotAssertion) -> None (_type_var_module_name, "CollectionTypeVar2", "plaintext"), ("_reexport_module_1", "ReexportClass", "plaintext"), (_abstract_module_name, "AbstractModuleClass", "plaintext"), - (_docstring_module_name, "EpydocDocstringClass", "epydoc"), (_docstring_module_name, "RestDocstringClass", "rest"), (_docstring_module_name, "NumpyDocstringClass", "numpydoc"), (_docstring_module_name, "GoogleDocstringClass", "google"), @@ -382,7 +368,6 @@ def test_global_functions(module_name: str, snapshot: SnapshotAssertion) -> None "CollectionTypeVar2", "ReexportClass", "AbstractModuleClass", - "EpydocDocstringClass", "RestDocstringClass", "NumpyDocstringClass", "GoogleDocstringClass", @@ -426,8 +411,6 @@ def test_class_methods(module_name: str, class_name: str, docstring_style: str, ("abstract_method_params", _abstract_module_name, "AbstractModuleClass", "plaintext"), ("abstract_static_method_params", _abstract_module_name, "AbstractModuleClass", "plaintext"), ("abstract_property_method", _abstract_module_name, "AbstractModuleClass", "plaintext"), - ("epydoc_docstring_func", _docstring_module_name, "EpydocDocstringClass", "epydoc"), - ("__init__", _docstring_module_name, "EpydocDocstringClass", "epydoc"), ("rest_docstring_func", _docstring_module_name, "RestDocstringClass", "rest"), ("__init__", _docstring_module_name, "RestDocstringClass", "rest"), ("numpy_docstring_func", _docstring_module_name, "NumpyDocstringClass", "numpydoc"), @@ -458,8 +441,6 @@ def test_class_methods(module_name: str, class_name: str, docstring_style: str, "abstract_method_params", "abstract_static_method_params", "abstract_property_method", - "epydoc_docstring_func", - "epydoc.__init__", "rest_docstring_func", "rest.__init__", "numpy_docstring_func", @@ -526,7 +507,6 @@ def test_function_parameters( ("abstract_method_params", _abstract_module_name, "AbstractModuleClass", "plaintext"), ("abstract_static_method_params", _abstract_module_name, "AbstractModuleClass", "plaintext"), ("abstract_property_method", _abstract_module_name, "AbstractModuleClass", "plaintext"), - ("epydoc_docstring_func", _docstring_module_name, "EpydocDocstringClass", "epydoc"), ("rest_docstring_func", _docstring_module_name, "RestDocstringClass", "rest"), ("numpy_docstring_func", _docstring_module_name, "NumpyDocstringClass", "numpydoc"), ("google_docstring_func", _docstring_module_name, "GoogleDocstringClass", "google"), @@ -567,7 +547,6 @@ def test_function_parameters( "abstract_method_params", "abstract_static_method_params", "abstract_property_method", - "epydoc_docstring_func", "rest_docstring_func", "numpy_docstring_func", "google_docstring_func", diff --git a/tests/safeds_stubgen/docstring_parsing/test_docstring_style.py b/tests/safeds_stubgen/docstring_parsing/test_docstring_style.py index dfe59d68..8eead154 100644 --- a/tests/safeds_stubgen/docstring_parsing/test_docstring_style.py +++ b/tests/safeds_stubgen/docstring_parsing/test_docstring_style.py @@ -4,7 +4,6 @@ def test_from_string() -> None: assert DocstringStyle.from_string("plaintext") == DocstringStyle.PLAINTEXT - assert DocstringStyle.from_string("epydoc") == DocstringStyle.EPYDOC assert DocstringStyle.from_string("google") == DocstringStyle.GOOGLE assert DocstringStyle.from_string("numpydoc") == DocstringStyle.NUMPYDOC assert DocstringStyle.from_string("rest") == DocstringStyle.REST diff --git a/tests/safeds_stubgen/docstring_parsing/test_epydoc_parser.py b/tests/safeds_stubgen/docstring_parsing/test_epydoc_parser.py deleted file mode 100644 index 271a98c3..00000000 --- a/tests/safeds_stubgen/docstring_parsing/test_epydoc_parser.py +++ /dev/null @@ -1,297 +0,0 @@ -from __future__ import annotations - -from pathlib import Path - -import pytest -from mypy import nodes -from safeds_stubgen.api_analyzer import Class, ParameterAssignment, get_classdef_definitions - -# noinspection PyProtectedMember -from safeds_stubgen.api_analyzer._get_api import _get_mypy_asts, _get_mypy_build -from safeds_stubgen.docstring_parsing import ( - ClassDocstring, - EpydocParser, - FunctionDocstring, - ParameterDocstring, - ResultDocstring, -) - -from tests.safeds_stubgen._helpers import get_specific_mypy_node - -# Setup -_test_dir = Path(__file__).parent.parent.parent -files = [str(Path(_test_dir / "data" / "docstring_parser_package" / "epydoc.py"))] -mypy_build = _get_mypy_build(files) -mypy_file = _get_mypy_asts( - build_result=mypy_build, - files=files, - package_paths=[], -)[0] - - -@pytest.fixture() -def epydoc_parser() -> EpydocParser: - return EpydocParser() - - -# ############################## Class Documentation ############################## # -@pytest.mark.parametrize( - ("class_name", "expected_class_documentation"), - [ - ( - "ClassWithDocumentation", - ClassDocstring( - description="Lorem ipsum. Code::\n\npass\n\nDolor sit amet.", - full_docstring="Lorem ipsum. Code::\n\n pass\n\nDolor sit amet.", - ), - ), - ( - "ClassWithoutDocumentation", - ClassDocstring( - description="", - full_docstring="", - ), - ), - ], - ids=[ - "class with documentation", - "class without documentation", - ], -) -def test_get_class_documentation( - epydoc_parser: EpydocParser, - class_name: str, - expected_class_documentation: ClassDocstring, -) -> None: - node = get_specific_mypy_node(mypy_file, class_name) - - assert isinstance(node, nodes.ClassDef) - assert epydoc_parser.get_class_documentation(node) == expected_class_documentation - - -# ############################## Function Documentation ############################## # -@pytest.mark.parametrize( - ("function_name", "expected_function_documentation"), - [ - ( - "function_with_documentation", - FunctionDocstring( - description="Lorem ipsum. Code::\n\npass\n\nDolor sit amet.", - full_docstring="Lorem ipsum. Code::\n\n pass\n\nDolor sit amet.", - ), - ), - ( - "function_without_documentation", - FunctionDocstring( - description="", - full_docstring="", - ), - ), - ], - ids=[ - "function with documentation", - "function without documentation", - ], -) -def test_get_function_documentation( - epydoc_parser: EpydocParser, - function_name: str, - expected_function_documentation: FunctionDocstring, -) -> None: - node = get_specific_mypy_node(mypy_file, function_name) - - assert isinstance(node, nodes.FuncDef) - assert epydoc_parser.get_function_documentation(node) == expected_function_documentation - - -# ############################## Parameter Documentation ############################## # -@pytest.mark.parametrize( - ("name", "is_class", "parameter_name", "parameter_assigned_by", "expected_parameter_documentation"), - [ - ( - "ClassWithParameters", - True, - "p", - ParameterAssignment.POSITION_OR_NAME, - ParameterDocstring( - type="int", - default_value="1", - description="foo defaults to 1", - ), - ), - ( - "ClassWithParameters", - True, - "missing", - ParameterAssignment.POSITION_OR_NAME, - ParameterDocstring( - type="", - default_value="", - description="", - ), - ), - ( - "function_with_parameters", - False, - "no_type_no_default", - ParameterAssignment.POSITION_OR_NAME, - ParameterDocstring( - type="", - default_value="", - description="no type and no default", - ), - ), - ( - "function_with_parameters", - False, - "type_no_default", - ParameterAssignment.POSITION_OR_NAME, - ParameterDocstring( - type="int", - default_value="", - description="type but no default", - ), - ), - ( - "function_with_parameters", - False, - "with_default", - ParameterAssignment.POSITION_OR_NAME, - ParameterDocstring( - type="int", - default_value="2", - description="foo that defaults to 2", - ), - ), - ( - "function_with_parameters", - False, - "missing", - ParameterAssignment.POSITION_OR_NAME, - ParameterDocstring(type="", default_value="", description=""), - ), - ], - ids=[ - "existing class parameter", - "missing class parameter", - "function parameter with no type and no default", - "function parameter with type and no default", - "function parameter with default", - "missing function parameter", - ], -) -def test_get_parameter_documentation( - epydoc_parser: EpydocParser, - name: str, - is_class: bool, - parameter_name: str, - parameter_assigned_by: ParameterAssignment, - expected_parameter_documentation: ParameterDocstring, -) -> None: - parent = None - node = get_specific_mypy_node(mypy_file, name) - if is_class: - assert isinstance(node, nodes.ClassDef) - class_doc = epydoc_parser.get_class_documentation(node) - parent = Class(id=node.fullname, name=node.name, superclasses=[], is_public=True, docstring=class_doc) - else: - assert isinstance(node, nodes.FuncDef) - - # Find the constructor - if isinstance(node, nodes.ClassDef): - for definition in get_classdef_definitions(node): - if isinstance(definition, nodes.FuncDef) and definition.name == "__init__": - node = definition - break - assert isinstance(node, nodes.FuncDef) - - parameter_documentation = epydoc_parser.get_parameter_documentation( - function_node=node, - parameter_name=parameter_name, - parameter_assigned_by=parameter_assigned_by, - parent_class=parent, - ) - - assert parameter_documentation == expected_parameter_documentation - - -# ############################## Attribute Documentation ############################## # -# Todo Epydoc: Attribute handling not yet implemented in dosctring_parser library, thus the tests -# also don't work yet and are therefore deactivated! -@pytest.mark.parametrize( - ("class_name", "attribute_name", "expected_parameter_documentation"), - [ - ( - "ClassWithAttributes", - "p", - ParameterDocstring( - type="int", - default_value="1", - description="foo defaults to 1", - ), - ), - ( - "ClassWithAttributesNoType", - "p", - ParameterDocstring( - type="", - default_value="1", - description="foo defaults to 1", - ), - ), - ], - ids=[ - "existing class attributes", - "existing class attributes no type", - ], -) -def xtest_get_attribute_documentation( - epydoc_parser: EpydocParser, - class_name: str, - attribute_name: str, - expected_parameter_documentation: ParameterDocstring, -) -> None: - node = get_specific_mypy_node(mypy_file, class_name) - assert isinstance(node, nodes.ClassDef) - docstring = epydoc_parser.get_class_documentation(node) - fake_class = Class(id="some_id", name="some_class", superclasses=[], is_public=True, docstring=docstring) - - attribute_documentation = epydoc_parser.get_attribute_documentation( - parent_class=fake_class, - attribute_name=attribute_name, - ) - - assert attribute_documentation == expected_parameter_documentation - - -# ############################## Result Documentation ############################## # -@pytest.mark.parametrize( - ("function_name", "expected_result_documentation"), - [ - ( - "function_with_result_value_and_type", - ResultDocstring(type="bool", description="return value"), - ), - ( - "function_with_result_value_no_type", - ResultDocstring(type="", description="return value"), - ), - ( - "function_without_result_value", - ResultDocstring(type="", description=""), - ), - ], - ids=[ - "existing return value and type", - "existing return value no type", - "function without return value", - ], -) -def test_get_result_documentation( - epydoc_parser: EpydocParser, - function_name: str, - expected_result_documentation: ResultDocstring, -) -> None: - node = get_specific_mypy_node(mypy_file, function_name) - assert isinstance(node, nodes.FuncDef) - assert epydoc_parser.get_result_documentation(node) == expected_result_documentation diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/TestStubFileGeneration.test_stub_creation[docstring_module].sdsstub b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/TestStubFileGeneration.test_stub_creation[docstring_module].sdsstub index 6abcb3db..4cb90541 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/TestStubFileGeneration.test_stub_creation[docstring_module].sdsstub +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/TestStubFileGeneration.test_stub_creation[docstring_module].sdsstub @@ -7,38 +7,6 @@ @PythonModule("tests.data.various_modules_package.docstring_module") package tests.data.variousModulesPackage.docstringModule -/** - * A class with a variety of different methods for calculations. (Epydoc). - * - * @ivar attr_1: Attribute of the calculator. (Epydoc) - * @type attr_1: str - * @param param_1: Parameter of the calculator. (Epydoc) - * @type param_1: str - */ -class EpydocDocstringClass( - @PythonName("param_1") param1: String -) { - @PythonName("attr_1") - static attr attr1: String - - /** - * This function checks if the sum of x and y is less than the value 10 and returns True if it is. (Epydoc). - * - * @param x: First integer value for the calculation. (Epydoc) - * @type x: int - * @param y: Second integer value for the calculation. (Epydoc) - * @type y: int - * @return: Checks if the sum of x and y is greater than 10. (Epydoc) - * @rtype: bool - */ - @Pure - @PythonName("epydoc_docstring_func") - fun epydocDocstringFunc( - x: Int, - y: Int - ) -> result1: Boolean -} - /** * A class with a variety of different methods for calculations. (ReST). * diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/test_stub_docstring_creation[epydoc-EPYDOC].sdsstub b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/test_stub_docstring_creation[epydoc-EPYDOC].sdsstub deleted file mode 100644 index 336a88ca..00000000 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/test_stub_docstring_creation[epydoc-EPYDOC].sdsstub +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Test module for docstring tests. - * - * A module for testing the various docstring types. - */ - -@PythonModule("tests.data.docstring_parser_package.epydoc") -package tests.data.docstringParserPackage.epydoc - -// TODO Result type information missing. -/** - * Lorem ipsum. Code:: - * - * pass - * - * Dolor sit amet. - */ -@Pure -@PythonName("function_with_documentation") -fun functionWithDocumentation() - -// TODO Result type information missing. -@Pure -@PythonName("function_without_documentation") -fun functionWithoutDocumentation() - -// TODO Result type information missing. -// TODO Safe-DS does not support variadic parameters. -// TODO Some parameter have no type information. -/** - * Lorem ipsum. - * - * Dolor sit amet. - * - * @param noTypeNoDefault no type and no default - * @param typeNoDefault type but no default - * @param withDefault foo that defaults to 2 - */ -@Pure -@PythonName("function_with_parameters") -fun functionWithParameters( - @PythonName("no_type_no_default") noTypeNoDefault, - @PythonName("type_no_default") typeNoDefault, - @PythonName("with_default") withDefault, - args: List, - kwargs: Map -) - -/** - * Lorem ipsum. - * - * Dolor sit amet. - * - * @result result1 return value - */ -@Pure -@PythonName("function_with_result_value_and_type") -fun functionWithResultValueAndType() -> result1: Boolean - -// TODO Result type information missing. -/** - * Lorem ipsum. - * - * Dolor sit amet. - */ -@Pure -@PythonName("function_with_result_value_no_type") -fun functionWithResultValueNoType() - -// TODO Result type information missing. -/** - * Lorem ipsum. - * - * Dolor sit amet. - */ -@Pure -@PythonName("function_without_result_value") -fun functionWithoutResultValue() - -/** - * Lorem ipsum. Code:: - * - * pass - * - * Dolor sit amet. - */ -class ClassWithDocumentation() - -class ClassWithoutDocumentation() - -/** - * Lorem ipsum. - * - * Dolor sit amet. - * - * @param p foo defaults to 1 - */ -// TODO Some parameter have no type information. -class ClassWithParameters( - p -) - -/** - * Lorem ipsum. - * - * Dolor sit amet. - */ -class ClassWithAttributes() { - static attr p: Int - static attr q: Int -} - -/** - * Lorem ipsum. - * - * Dolor sit amet. - */ -class ClassWithAttributesNoType() { - static attr p: Int - static attr q: Int -} - -class ClassWithMethod() { - /** - * Lorem ipsum. - * - * Dolor sit amet. - */ - @PythonName("property_method_with_docstring") attr propertyMethodWithDocstring: Boolean - - // TODO Some parameter have no type information. - /** - * Lorem ipsum. - * - * Dolor sit amet. - * - * @param a type but no default - * - * @result result1 return value - */ - @Pure - @PythonName("method_with_docstring") - fun methodWithDocstring( - a - ) -> result1: Boolean -} - -/** - * Lorem ipsum. - * - * Dolor sit amet. - */ -enum EnumDocstring diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index 3c896159..ae592123 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -144,7 +144,6 @@ def test_convert_name_to_convention( @pytest.mark.parametrize( ("filename", "docstring_style"), [ - ("epydoc", DocstringStyle.EPYDOC), ("full_docstring", DocstringStyle.PLAINTEXT), ("googledoc", DocstringStyle.GOOGLE), ("numpydoc", DocstringStyle.NUMPYDOC),