Skip to content

Commit

Permalink
Intern classes won't be displayed as superclasses in stub files
Browse files Browse the repository at this point in the history
  • Loading branch information
Masara committed Mar 4, 2024
1 parent bc9309c commit ccf5a12
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
48 changes: 25 additions & 23 deletions src/safeds_stubgen/stubs_generator/_generate_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,20 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st
superclass_names = []
for superclass in superclasses:
superclass_name = superclass.split(".")[-1]
superclass_names.append(superclass_name)
self._add_to_imports(superclass)

# If the superclass was not added to the module_imports through the _add_to_imports method, it means
# that the superclass is a class from the same module.
# For internal superclasses, we have to add their public members to subclasses.
superclass_methods_text += self._create_internal_class_methods_string(superclass, inner_indentations)
if superclass not in self.module_imports and is_internal(superclass_name):
# If the superclass was not added to the module_imports through the _add_to_imports method, it means
# that the superclass is a class from the same module.
# For internal superclasses, we have to add their public members to subclasses.
superclass_methods_text += self._create_internal_class_methods_string(
superclass=superclass,
inner_indentations=inner_indentations
)
else:
superclass_names.append(superclass_name)

superclass_info = f" sub {', '.join(superclass_names)}"
superclass_info = f" sub {', '.join(superclass_names)}" if superclass_names else ""

if len(superclasses) > 1:
self._current_todo_msgs.add("multiple_inheritance")
Expand Down Expand Up @@ -761,25 +766,22 @@ def _create_type_string(self, type_data: dict | None) -> str:
raise ValueError(f"Unexpected type: {kind}") # pragma: no cover

def _create_internal_class_methods_string(self, superclass: str, inner_indentations: str) -> str:
superclass_methods_text = ""
superclass_name = superclass.split(".")[-1]
superclass_class = None
if superclass not in self.module_imports and is_internal(superclass_name):
superclass_class = self._get_class_in_module(superclass_name)
superclass_methods_text = self._create_class_method_string(
superclass_class.methods,
inner_indentations,
is_internal_class=True,
)

if superclass_class is not None:
for superclass_superclass in superclass_class.superclasses:
name = superclass_superclass.split(".")[-1]
if is_internal(name):
superclass_methods_text += self._create_internal_class_methods_string(
superclass_superclass,
inner_indentations,
)
superclass_class = self._get_class_in_module(superclass_name)
superclass_methods_text = self._create_class_method_string(
superclass_class.methods,
inner_indentations,
is_internal_class=True,
)

for superclass_superclass in superclass_class.superclasses:
name = superclass_superclass.split(".")[-1]
if is_internal(name):
superclass_methods_text += self._create_internal_class_methods_string(
superclass_superclass,
inner_indentations,
)

return superclass_methods_text

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from variousModulesPackage.aliasing.aliasingModule3 import ImportMeAliasingModul

class AliasingModuleClassB()

class AliasingModuleClassC() sub _AliasingModuleClassA {
class AliasingModuleClassC() {
@PythonName("typed_alias_attr")
static attr typedAliasAttr: AliasingModuleClassB
// TODO An internal class must not be used as a type in a public class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PublicSuperClass() {

class PublicSubClass() sub PublicSuperClass

class PublicSubClass2() sub _PrivateInternalClass {
class PublicSubClass2() {
@Pure
@PythonName("public_internal_class_method")
fun publicInternalClassMethod(
Expand All @@ -21,15 +21,15 @@ class PublicSubClass2() sub _PrivateInternalClass {
fun publicSubclassMethod() -> result1: String
}

class PublicSubClassFromNested() sub _PrivateInternalNestedClass {
class PublicSubClassFromNested() {
@Pure
@PythonName("public_internal_nested_class_method")
fun publicInternalNestedClassMethod(
a: Nothing?
) -> result1: Boolean
}

class InheritTransitively() sub _TransitiveInternalClassB {
class InheritTransitively() {
@Pure
@PythonName("transitive_class_fun")
fun transitiveClassFun(
Expand Down

0 comments on commit ccf5a12

Please sign in to comment.