Skip to content

Commit

Permalink
[WIP] Some bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Masara committed Sep 14, 2023
1 parent e35d277 commit f081fa6
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/safeds_stubgen/api_analyzer/_ast_visitor_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def enter_funcdef(self, node: FuncDef) -> None:

# Create results
ret_type = "Any"
if hasattr(node, "type"):
if getattr(node, "type", None):
ret_type = str(node.type.ret_type)

result = Result(
Expand Down Expand Up @@ -321,19 +321,39 @@ def parse_attributes(self, lvalue: NameExpr | MemberExpr, is_static=True) -> lis
attributes: list[Attribute] = []

if hasattr(lvalue, "name"):
if self.check_attribute_already_defined(lvalue, lvalue.name):
return attributes

attributes.append(
self.create_attribute(lvalue, is_static)
)

elif hasattr(lvalue, "items"):
lvalues = [item for item in lvalue.items]
for lvalue in lvalues:
for lvalue_ in lvalues:
if self.check_attribute_already_defined(lvalue_, lvalue_.name):
continue

attributes.append(
self.create_attribute(lvalue, is_static)
self.create_attribute(lvalue_, is_static)
)

return attributes

def check_attribute_already_defined(self, lvalue: NameExpr, value_name: str) -> bool:
# If node is None, it's possible that the attribute was already defined once
if lvalue.node is None:
parent = self.__declaration_stack[-1]
if isinstance(parent, Function):
parent = self.__declaration_stack[-2]

for attribute in parent.attributes:
if value_name == attribute.name:
return True

raise ValueError(f"The attribute {value_name} has no value.")
return False

def create_attribute(self, attribute, is_static: bool) -> Attribute:
# Get name and qname
name = attribute.name
Expand Down

0 comments on commit f081fa6

Please sign in to comment.