Skip to content

Commit

Permalink
style: apply automated linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
megalinter-bot authored and Masara committed Aug 18, 2024
1 parent da57f5d commit bffd317
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
22 changes: 16 additions & 6 deletions src/safeds_stubgen/api_analyzer/_ast_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,12 @@ def _infer_type_from_return_stmts(self, func_node: mp_nodes.FuncDef) -> sds_type
if isinstance(return_stmt.expr.node, mp_nodes.FuncDef | mp_nodes.Decorator):
# In this case we have an inner function which the outer function returns.
continue
if (isinstance(return_stmt.expr.node, mp_nodes.Var) and hasattr(return_stmt.expr, "name") and
return_stmt.expr.name in func_node.arg_names and return_stmt.expr.node.type is not None):
if (
isinstance(return_stmt.expr.node, mp_nodes.Var)
and hasattr(return_stmt.expr, "name")
and return_stmt.expr.name in func_node.arg_names
and return_stmt.expr.node.type is not None
):
# In this case the return value is a parameter of the function
type_ = self.mypy_type_to_abstract_type(return_stmt.expr.node.type)
types.append(type_)
Expand All @@ -670,15 +674,21 @@ def _infer_type_from_return_stmts(self, func_node: mp_nodes.FuncDef) -> sds_type
continue

if not isinstance(cond_branch, mp_nodes.CallExpr | mp_nodes.MemberExpr):
if (hasattr(cond_branch, "node") and isinstance(cond_branch.node, mp_nodes.Var) and
cond_branch.node.type is not None):
if (
hasattr(cond_branch, "node")
and isinstance(cond_branch.node, mp_nodes.Var)
and cond_branch.node.type is not None
):
# In this case the return value is a parameter of the function
type_ = self.mypy_type_to_abstract_type(cond_branch.node.type)
else:
type_ = mypy_expression_to_sds_type(cond_branch)
types.append(type_)
elif (return_stmt.expr is not None and hasattr(return_stmt.expr, "node") and
getattr(return_stmt.expr.node, "is_self", False)):
elif (
return_stmt.expr is not None
and hasattr(return_stmt.expr, "node")
and getattr(return_stmt.expr.node, "is_self", False)
):
# The result type is an instance of the parent class
expr_type = return_stmt.expr.node.type.type
types.append(sds_types.NamedType(name=expr_type.name, qname=expr_type.fullname))
Expand Down
3 changes: 1 addition & 2 deletions src/safeds_stubgen/api_analyzer/_mypy_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def get_argument_kind(arg: mp_nodes.Argument) -> ParameterAssignment:


def find_stmts_recursive(
stmt_type: type[mp_nodes.Statement],
stmts: list[mp_nodes.Statement] | list[mp_nodes.Block]
stmt_type: type[mp_nodes.Statement], stmts: list[mp_nodes.Statement] | list[mp_nodes.Block],
) -> list[mp_nodes.Statement]:
found_stmts = []
for stmt in stmts:
Expand Down

0 comments on commit bffd317

Please sign in to comment.