data.SourceClass

 1from .SourceFunction import SourceFunction
 2from .SourceVariable import SourceVariable
 3
 4
 5class SourceClass:
 6    """
 7    Data class representing a python class.
 8    """
 9
10    def __init__(self) -> None:
11        self.name: str = ''
12        self.variables: list[SourceVariable] = []
13        self.methods: list[SourceFunction] = []
14        self.bases: list[str] = []
15
16    def get_dependencies(self) -> set[str]:
17        """
18        Generates a list of dependencies.
19
20        :return: All dependencies of the class.
21        """
22        return {inner for outer in self.variables for inner in outer.get_dependencies()}.union(
23            {inner for outer in self.methods for inner in outer.get_dependencies()}
24        )
25
26    def __str__(self) -> str:
27        self.variables.sort(key=lambda x: x.name)
28        self.methods.sort(key=lambda x: x.name)
29        static_variables = '\n'.join([
30            '+ ' + str(variable) for variable in self.variables if variable.static
31        ])
32        instance_variables = '\n'.join([
33            '+ ' + str(variable) for variable in self.variables if not variable.static
34        ])
35        static_methods = '\n'.join([
36            '+ ' + str(method) for method in self.methods if method.static
37        ])
38        instance_methods = '\n'.join([
39            '+ ' + str(method) for method in self.methods if not method.static
40        ])
41        return 'class ' + \
42            self.name + \
43            ' {\n' + \
44            '\n__\n'.join([
45                x
46                for x in (static_variables, instance_variables, static_methods, instance_methods)
47                if x
48            ]) + \
49            '\n}'
class SourceClass:
 6class SourceClass:
 7    """
 8    Data class representing a python class.
 9    """
10
11    def __init__(self) -> None:
12        self.name: str = ''
13        self.variables: list[SourceVariable] = []
14        self.methods: list[SourceFunction] = []
15        self.bases: list[str] = []
16
17    def get_dependencies(self) -> set[str]:
18        """
19        Generates a list of dependencies.
20
21        :return: All dependencies of the class.
22        """
23        return {inner for outer in self.variables for inner in outer.get_dependencies()}.union(
24            {inner for outer in self.methods for inner in outer.get_dependencies()}
25        )
26
27    def __str__(self) -> str:
28        self.variables.sort(key=lambda x: x.name)
29        self.methods.sort(key=lambda x: x.name)
30        static_variables = '\n'.join([
31            '+ ' + str(variable) for variable in self.variables if variable.static
32        ])
33        instance_variables = '\n'.join([
34            '+ ' + str(variable) for variable in self.variables if not variable.static
35        ])
36        static_methods = '\n'.join([
37            '+ ' + str(method) for method in self.methods if method.static
38        ])
39        instance_methods = '\n'.join([
40            '+ ' + str(method) for method in self.methods if not method.static
41        ])
42        return 'class ' + \
43            self.name + \
44            ' {\n' + \
45            '\n__\n'.join([
46                x
47                for x in (static_variables, instance_variables, static_methods, instance_methods)
48                if x
49            ]) + \
50            '\n}'

Data class representing a python class.

name: str
bases: list[str]
def get_dependencies(self) -> set[str]:
17    def get_dependencies(self) -> set[str]:
18        """
19        Generates a list of dependencies.
20
21        :return: All dependencies of the class.
22        """
23        return {inner for outer in self.variables for inner in outer.get_dependencies()}.union(
24            {inner for outer in self.methods for inner in outer.get_dependencies()}
25        )

Generates a list of dependencies.

Returns

All dependencies of the class.