Skip to content

Commit

Permalink
fix: Docstrings have the correct indentation for nested classes (stub…
Browse files Browse the repository at this point in the history
…s) (#114)

Closes #113

### Summary of Changes

Fixed the wrong indentation for docstrings in nested classes.
  • Loading branch information
Masara authored Apr 20, 2024
1 parent 4554a56 commit c7b8550
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/safeds_stubgen/stubs_generator/_generate_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st
class_text += self._create_class_method_string(class_.methods, inner_indentations)

# Docstring
docstring = self._create_sds_docstring(class_.docstring, "", node=class_)
docstring = self._create_sds_docstring(class_.docstring, class_indentation, node=class_)

# If the does not have a body, we just return the docstring and signature line
if not class_text:
Expand Down
5 changes: 4 additions & 1 deletion tests/data/various_modules_package/class_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ def f1_2(): ...

class ClassModuleClassD:
class ClassModuleNestedClassE:
"""Docstring of the nested class E."""
nested_attr_1: None
_nested_attr_2: None

def class_e_func(self): ...
def class_e_func(self):
"""Docstring of func of nested class E"""
...

class _ClassModulePrivateDoubleNestedClassF:
def _class_f_func(self): ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,8 +1257,8 @@
list([
dict({
'docstring': dict({
'description': '',
'full_docstring': '',
'description': 'Docstring of func of nested class E',
'full_docstring': 'Docstring of func of nested class E',
}),
'id': 'tests/data/various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func',
'is_class_method': False,
Expand Down Expand Up @@ -2141,8 +2141,8 @@
]),
'constructor': None,
'docstring': dict({
'description': '',
'full_docstring': '',
'description': 'Docstring of the nested class E.',
'full_docstring': 'Docstring of the nested class E.',
}),
'id': 'tests/data/various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE',
'inherits_from_exception': False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class ClassModuleClassC() sub ClassModuleEmptyClassA, ClassModuleClassB, yetAnot
}

class ClassModuleClassD() {
/**
* Docstring of the nested class E.
*/
class ClassModuleNestedClassE() {
@PythonName("nested_attr_1")
static attr nestedAttr1: Nothing?
Expand All @@ -35,6 +38,9 @@ class ClassModuleClassD() {
class ClassModulePrivateDoubleNestedClassF()

// TODO Result type information missing.
/**
* Docstring of func of nested class E
*/
@Pure
@PythonName("class_e_func")
fun classEFunc()
Expand Down

0 comments on commit c7b8550

Please sign in to comment.