From 89d42a9d45e60fff851e4c7dd181dff29105b0c5 Mon Sep 17 00:00:00 2001 From: Arsam Date: Sat, 17 Aug 2024 18:11:36 +0200 Subject: [PATCH] codecov fix --- .../api_analyzer/_ast_visitor.py | 48 +++++++++---------- .../function_module.py | 5 ++ .../__snapshots__/test__get_api.ambr | 23 +++++++++ ...est_stub_creation[function_module].sdsstub | 8 ++++ 4 files changed, 59 insertions(+), 25 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index a07dc889..1d826a4c 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -597,36 +597,34 @@ def _remove_assignments(func_defn: list, type_: AbstractType) -> AbstractType: found_types = [type_] for found_type in found_types: - if not isinstance(found_type, sds_types.NamedType): - continue - - is_assignment = False - found_type_name = found_type.name - - for defn in func_defn: - if not isinstance(defn, mp_nodes.AssignmentStmt): - continue - - for lvalue in defn.lvalues: - if isinstance(lvalue, mp_nodes.TupleExpr): - name_expressions = lvalue.items - else: - name_expressions = [lvalue] - - for expr in name_expressions: - if isinstance(expr, mp_nodes.NameExpr) and found_type_name == expr.name: - is_assignment = True + if isinstance(found_type, sds_types.NamedType): + is_assignment = False + found_type_name = found_type.name + + for defn in func_defn: + if not isinstance(defn, mp_nodes.AssignmentStmt): + continue + + for lvalue in defn.lvalues: + if isinstance(lvalue, mp_nodes.TupleExpr): + name_expressions = lvalue.items + else: + name_expressions = [lvalue] + + for expr in name_expressions: + if isinstance(expr, mp_nodes.NameExpr) and found_type_name == expr.name: + is_assignment = True + break + if is_assignment: break + if is_assignment: break if is_assignment: - break - - if is_assignment: - actual_types.append(sds_types.UnknownType()) - else: - actual_types.append(found_type) + actual_types.append(sds_types.UnknownType()) + else: + actual_types.append(found_type) if len(actual_types) > 1: type_ = sds_types.TupleType(types=actual_types) diff --git a/tests/data/various_modules_package/function_module.py b/tests/data/various_modules_package/function_module.py index ede04b65..8357b76b 100644 --- a/tests/data/various_modules_package/function_module.py +++ b/tests/data/various_modules_package/function_module.py @@ -222,3 +222,8 @@ def _f(x: int, y: int) -> int: g, f = _f(a, b) Cxy = _f(g, f)**2 return Cxy, f + + +def ignore_assignment2(a: int, b: int): + Cxy = 3**2 + return Cxy diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index afec6e0c..14b5962c 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -6094,6 +6094,28 @@ 'tests/data/various_modules_package/function_module/ignore_assignment/result_2', ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'examples': list([ + ]), + 'full_docstring': '', + }), + 'id': 'tests/data/various_modules_package/function_module/ignore_assignment2', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'ignore_assignment2', + 'parameters': list([ + 'tests/data/various_modules_package/function_module/ignore_assignment2/a', + 'tests/data/various_modules_package/function_module/ignore_assignment2/b', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), dict({ 'docstring': dict({ 'description': '', @@ -7571,6 +7593,7 @@ 'tests/data/various_modules_package/function_module/result_from_outside_the_package', 'tests/data/various_modules_package/function_module/ret_conditional_statement', 'tests/data/various_modules_package/function_module/ignore_assignment', + 'tests/data/various_modules_package/function_module/ignore_assignment2', ]), 'id': 'tests/data/various_modules_package/function_module', 'name': 'function_module', diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/TestStubFileGeneration.test_stub_creation[function_module].sdsstub b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/TestStubFileGeneration.test_stub_creation[function_module].sdsstub index c01499f0..13562faa 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/TestStubFileGeneration.test_stub_creation[function_module].sdsstub +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs/TestStubFileGeneration.test_stub_creation[function_module].sdsstub @@ -272,6 +272,14 @@ fun ignoreAssignment( b: Int ) -> (result1: unknown, result2: unknown) +// TODO Result type information missing. +@Pure +@PythonName("ignore_assignment2") +fun ignoreAssignment2( + a: Int, + b: Int +) + class FunctionModuleClassA() // TODO Some parameter have no type information.