From d8fd2b1948f9a5432d4ffa8fad712b00984efef4 Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Sat, 11 Apr 2026 15:56:14 +0200 Subject: [PATCH] Bug fix: core.python.arguments.PythonASTArgumentsListParser.to_argument_list failed if a type annotation is not a single name --- src/jcloud_docsgen/core/python/arguments.py | 10 +++++----- .../arguments/test_PythonASTArgumentsListParser.py | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/jcloud_docsgen/core/python/arguments.py b/src/jcloud_docsgen/core/python/arguments.py index 43ca7cd..3410921 100644 --- a/src/jcloud_docsgen/core/python/arguments.py +++ b/src/jcloud_docsgen/core/python/arguments.py @@ -127,26 +127,26 @@ class PythonASTArgumentsListParser: if arg.annotation is None: arguments.append(PythonFunctionArgument(arg.arg, PythonArgumentKind.POSITIONAL_ONLY, None, None)) else: - arguments.append(PythonFunctionArgument(arg.arg, PythonArgumentKind.POSITIONAL_ONLY, None, arg.annotation.id)) + arguments.append(PythonFunctionArgument(arg.arg, PythonArgumentKind.POSITIONAL_ONLY, None, ast.unparse(arg.annotation))) for arg in self.ast_arguments_list.args: if arg.annotation is None: arguments.append(PythonFunctionArgument(arg.arg, PythonArgumentKind.NORMAL, None, None)) else: - arguments.append(PythonFunctionArgument(arg.arg, PythonArgumentKind.NORMAL, None, arg.annotation.id)) + arguments.append(PythonFunctionArgument(arg.arg, PythonArgumentKind.NORMAL, None, ast.unparse(arg.annotation))) if self.ast_arguments_list.vararg is not None: if self.ast_arguments_list.vararg.annotation is None: arguments.append(PythonFunctionArgument(self.ast_arguments_list.vararg.arg, PythonArgumentKind.VARARG, None, None)) else: - arguments.append(PythonFunctionArgument(self.ast_arguments_list.vararg.arg, PythonArgumentKind.VARARG, None, self.ast_arguments_list.vararg.annotation.id)) + arguments.append(PythonFunctionArgument(self.ast_arguments_list.vararg.arg, PythonArgumentKind.VARARG, None, ast.unparse(self.ast_arguments_list.vararg.annotation))) for arg in self.ast_arguments_list.kwonlyargs: if arg.annotation is None: arguments.append(PythonFunctionArgument(arg.arg, PythonArgumentKind.KEYWORD_ONLY, None, None)) else: - arguments.append(PythonFunctionArgument(arg.arg, PythonArgumentKind.KEYWORD_ONLY, None, arg.annotation.id)) + arguments.append(PythonFunctionArgument(arg.arg, PythonArgumentKind.KEYWORD_ONLY, None, ast.unparse(arg.annotation))) if self.ast_arguments_list.kwarg is not None: if self.ast_arguments_list.kwarg.annotation is None: arguments.append(PythonFunctionArgument(self.ast_arguments_list.kwarg.arg, PythonArgumentKind.KWARGS, None, None)) else: - arguments.append(PythonFunctionArgument(self.ast_arguments_list.kwarg.arg, PythonArgumentKind.KWARGS, None, self.ast_arguments_list.kwarg.annotation.id)) + arguments.append(PythonFunctionArgument(self.ast_arguments_list.kwarg.arg, PythonArgumentKind.KWARGS, None, ast.unparse(self.ast_arguments_list.kwarg.annotation))) return arguments \ No newline at end of file diff --git a/tests/unit/core/python/arguments/test_PythonASTArgumentsListParser.py b/tests/unit/core/python/arguments/test_PythonASTArgumentsListParser.py index ecaf5c3..d280855 100644 --- a/tests/unit/core/python/arguments/test_PythonASTArgumentsListParser.py +++ b/tests/unit/core/python/arguments/test_PythonASTArgumentsListParser.py @@ -32,6 +32,7 @@ def argument_list(argument_list: str) -> ast.arguments: @pytest.mark.parametrize('ast_arguments_list,expected', [ (argument_list('a'), [PythonFunctionArgument('a', PythonArgumentKind.NORMAL, None, None)]), (argument_list('a: str'), [PythonFunctionArgument('a', PythonArgumentKind.NORMAL, None, 'str')]), + (argument_list('a: str | int'), [PythonFunctionArgument('a', PythonArgumentKind.NORMAL, None, 'str | int')]), (argument_list('a: str, b'), [ PythonFunctionArgument('a', PythonArgumentKind.NORMAL, None, 'str'), PythonFunctionArgument('b', PythonArgumentKind.NORMAL, None, None)