Skip to content

Commit

Permalink
Show default values in diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
Domi04151309 committed Oct 30, 2023
1 parent 0556f24 commit 7c12bd0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 10 additions & 2 deletions data/SourceVariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ class SourceVariable:
Data class representing a python variable.
"""

def __init__(self, name: str, data_type: SourceType, static: bool = False) -> None:
def __init__(
self,
name: str,
data_type: SourceType,
static: bool = False,
default: str | None = None
) -> None:
self.static: bool = static
self.name: str = name
self.type: SourceType = data_type
self.default: str | None = default

def get_dependencies(self) -> set[str]:
"""
Expand All @@ -22,4 +29,5 @@ def get_dependencies(self) -> set[str]:
def __str__(self) -> str:
return ('{static}' if self.static else '') + \
self.name + \
(': <color:MidnightBlue>' + str(self.type) + '</color>' if str(self.type) else '')
(': <color:MidnightBlue>' + str(self.type) + '</color>' if str(self.type) else '') + \
(' = ' + self.default if self.default else '')
8 changes: 7 additions & 1 deletion utils/ModuleParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ def get_function(node: FunctionDef) -> SourceFunction:
function.static = True
for i, arg in enumerate(node.args.args):
annotation = annotation_to_type(node.args.annotations[i])
try:
default = str(node.args.default_value(arg.name).value)
except astroid.exceptions.NoDefault:
default = None
function.params.append(
SourceVariable(
arg.name,
annotation
annotation,
False,
default
)
)
return function
Expand Down

0 comments on commit 7c12bd0

Please sign in to comment.