diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 3423c31d..801497ce 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -721,6 +721,8 @@ def _create_type_string(self, type_data: dict | None) -> str: for i, type_ in enumerate(return_type["types"]) ] return_type_string = f"({', '.join(return_types)})" + elif return_type["kind"] == "NamedType" and return_type["name"] == "None": + return f"({', '.join(params)}) -> ()" else: result_name = _convert_name_to_convention("result_1", self.naming_convention) return_type_string = f"{result_name}: {self._create_type_string(return_type)}" diff --git a/tests/data/various_modules_package/function_module.py b/tests/data/various_modules_package/function_module.py index 29d1a2f2..5a781233 100644 --- a/tests/data/various_modules_package/function_module.py +++ b/tests/data/various_modules_package/function_module.py @@ -54,7 +54,8 @@ def params( optional: Optional[int], tuple_: tuple[int, str, bool], literal: Literal["Some String"], - any_: Any + any_: Any, + callable_none: Callable[[int, float], None] | None, ): ... @@ -75,7 +76,7 @@ def params_with_default_value( optional: Optional[int] = None, tuple_: tuple[int, str, bool] = (1, "2", True), literal: Literal["Some String"] = "Some String", - any_: Any = False + any_: Any = False, ): ... 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 deab9031..3c6c1319 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -3729,6 +3729,48 @@ 'qname': 'builtins.bool', }), }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': None, + }), + 'id': 'tests/data/various_modules_package/function_module/params/callable_none', + 'is_optional': False, + 'name': 'callable_none', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'CallableType', + 'parameter_types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'float', + 'qname': 'builtins.float', + }), + ]), + 'return_type': dict({ + 'kind': 'NamedType', + 'name': 'None', + 'qname': 'builtins.None', + }), + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + 'qname': 'builtins.None', + }), + ]), + }), + }), dict({ 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, @@ -6021,6 +6063,7 @@ 'tests/data/various_modules_package/function_module/params/tuple_', 'tests/data/various_modules_package/function_module/params/literal', 'tests/data/various_modules_package/function_module/params/any_', + 'tests/data/various_modules_package/function_module/params/callable_none', ]), 'reexported_by': list([ ]), 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 4595d81c..758a2001 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 @@ -30,7 +30,8 @@ fun params( optional: Int?, @PythonName("tuple_") tuple: Tuple, `literal`: literal<"Some String">, - @PythonName("any_") any: Any + @PythonName("any_") any: Any, + @PythonName("callable_none") callableNone: (param1: Int, param2: Float) -> ()? ) // TODO Result type information missing.