Skip to content

Commit

Permalink
fix: Nested internal classes won't create stubs (#154)
Browse files Browse the repository at this point in the history
Closes #143 

### Summary of Changes
Fixed a bug where nested internal classes would create stubs even though
stubs should not be created for these internal classes.
  • Loading branch information
Masara authored Jun 20, 2024
1 parent 48ad9da commit d75983a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
15 changes: 9 additions & 6 deletions src/safeds_stubgen/stubs_generator/_stub_string_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,15 @@ def _create_class_string(self, class_: Class, class_indentation: str = "", in_re

# Inner classes
for inner_class in class_.classes:
class_string = self._create_class_string(
class_=inner_class,
class_indentation=inner_indentations,
in_reexport_module=in_reexport_module,
)
class_text += f"\n{class_string}\n"
if inner_class.is_public:
# We set in_reexport_module to True since nested classes alone can't be reexported and are bound to
# their parent class
class_string = self._create_class_string(
class_=inner_class,
class_indentation=inner_indentations,
in_reexport_module=True,
)
class_text += f"\n{class_string}\n"

# Methods
class_method_text, added_class_methods = self._create_class_method_string(class_.methods, inner_indentations)
Expand Down
3 changes: 3 additions & 0 deletions tests/data/various_modules_package/class_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def class_e_func(self):
class _ClassModulePrivateDoubleNestedClassF:
def _class_f_func(self): ...

class _PrivateNestedClass:
...


class _ClassModulePrivateClassG:
_attr_1: float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,7 @@
]),
'classes': list([
'tests/data/various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE',
'tests/data/various_modules_package/class_module/ClassModuleClassD/_PrivateNestedClass',
]),
'constructor': None,
'docstring': dict({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ class ClMCD() {
@PythonName("nested_attr_1")
static attr nestedAttr1: Nothing?

@PythonName("_ClassModulePrivateDoubleNestedClassF")
class ClassModulePrivateDoubleNestedClassF()

// TODO Result type information missing.
/**
* Docstring of func of nested class E
Expand Down

0 comments on commit d75983a

Please sign in to comment.