Bug fix: add support for default values in core.python.arguments.PythonASTArgumentsListParser.to_argument_list

This commit is contained in:
2026-04-12 19:30:04 +02:00
parent e4fe88b60b
commit ed3b47bd81
2 changed files with 85 additions and 6 deletions
@@ -159,6 +159,73 @@ def argument_list(argument_list: str) -> ast.arguments:
PythonFunctionArgument('d', PythonArgumentKind.KEYWORD_ONLY, None, 'dict'),
PythonFunctionArgument('kwargs', PythonArgumentKind.KWARGS, None, 'set'),
]),
(argument_list('a = 1, b = \'a\', /, *args, c = None, d = True, **kwargs'), [
PythonFunctionArgument('a', PythonArgumentKind.POSITIONAL_ONLY, '1', None),
PythonFunctionArgument('b', PythonArgumentKind.POSITIONAL_ONLY, '\'a\'', None),
PythonFunctionArgument('args', PythonArgumentKind.VARARG, None, None),
PythonFunctionArgument('c', PythonArgumentKind.KEYWORD_ONLY, 'None', None),
PythonFunctionArgument('d', PythonArgumentKind.KEYWORD_ONLY, 'True', None),
PythonFunctionArgument('kwargs', PythonArgumentKind.KWARGS, None, None),
]),
(argument_list('a, b = \'a\', /, *args, c = None, d = True, **kwargs'), [
PythonFunctionArgument('a', PythonArgumentKind.POSITIONAL_ONLY, None, None),
PythonFunctionArgument('b', PythonArgumentKind.POSITIONAL_ONLY, '\'a\'', None),
PythonFunctionArgument('args', PythonArgumentKind.VARARG, None, None),
PythonFunctionArgument('c', PythonArgumentKind.KEYWORD_ONLY, 'None', None),
PythonFunctionArgument('d', PythonArgumentKind.KEYWORD_ONLY, 'True', None),
PythonFunctionArgument('kwargs', PythonArgumentKind.KWARGS, None, None),
]),
(argument_list('a, b , /, *args, c = None, d = True, **kwargs'), [
PythonFunctionArgument('a', PythonArgumentKind.POSITIONAL_ONLY, None, None),
PythonFunctionArgument('b', PythonArgumentKind.POSITIONAL_ONLY, None, None),
PythonFunctionArgument('args', PythonArgumentKind.VARARG, None, None),
PythonFunctionArgument('c', PythonArgumentKind.KEYWORD_ONLY, 'None', None),
PythonFunctionArgument('d', PythonArgumentKind.KEYWORD_ONLY, 'True', None),
PythonFunctionArgument('kwargs', PythonArgumentKind.KWARGS, None, None),
]),
(argument_list('a, b , /, *args, c, d = True, **kwargs'), [
PythonFunctionArgument('a', PythonArgumentKind.POSITIONAL_ONLY, None, None),
PythonFunctionArgument('b', PythonArgumentKind.POSITIONAL_ONLY, None, None),
PythonFunctionArgument('args', PythonArgumentKind.VARARG, None, None),
PythonFunctionArgument('c', PythonArgumentKind.KEYWORD_ONLY, None, None),
PythonFunctionArgument('d', PythonArgumentKind.KEYWORD_ONLY, 'True', None),
PythonFunctionArgument('kwargs', PythonArgumentKind.KWARGS, None, None),
]),
(argument_list('a, b , /, *args, c, d, **kwargs'), [
PythonFunctionArgument('a', PythonArgumentKind.POSITIONAL_ONLY, None, None),
PythonFunctionArgument('b', PythonArgumentKind.POSITIONAL_ONLY, None, None),
PythonFunctionArgument('args', PythonArgumentKind.VARARG, None, None),
PythonFunctionArgument('c', PythonArgumentKind.KEYWORD_ONLY, None, None),
PythonFunctionArgument('d', PythonArgumentKind.KEYWORD_ONLY, None, None),
PythonFunctionArgument('kwargs', PythonArgumentKind.KWARGS, None, None),
]),
(argument_list('a, b , /, *args, c = None, d, **kwargs'), [
PythonFunctionArgument('a', PythonArgumentKind.POSITIONAL_ONLY, None, None),
PythonFunctionArgument('b', PythonArgumentKind.POSITIONAL_ONLY, None, None),
PythonFunctionArgument('args', PythonArgumentKind.VARARG, None, None),
PythonFunctionArgument('c', PythonArgumentKind.KEYWORD_ONLY, 'None', None),
PythonFunctionArgument('d', PythonArgumentKind.KEYWORD_ONLY, None, None),
PythonFunctionArgument('kwargs', PythonArgumentKind.KWARGS, None, None),
]),
(argument_list('a = 1, b , /, *args, c = None, d, **kwargs'), [
PythonFunctionArgument('a', PythonArgumentKind.POSITIONAL_ONLY, '1', None),
PythonFunctionArgument('b', PythonArgumentKind.POSITIONAL_ONLY, None, None),
PythonFunctionArgument('args', PythonArgumentKind.VARARG, None, None),
PythonFunctionArgument('c', PythonArgumentKind.KEYWORD_ONLY, 'None', None),
PythonFunctionArgument('d', PythonArgumentKind.KEYWORD_ONLY, None, None),
PythonFunctionArgument('kwargs', PythonArgumentKind.KWARGS, None, None),
]),
(argument_list('a = 1, b , /, *args, c = None, d = False, **kwargs'), [
PythonFunctionArgument('a', PythonArgumentKind.POSITIONAL_ONLY, '1', None),
PythonFunctionArgument('b', PythonArgumentKind.POSITIONAL_ONLY, None, None),
PythonFunctionArgument('args', PythonArgumentKind.VARARG, None, None),
PythonFunctionArgument('c', PythonArgumentKind.KEYWORD_ONLY, 'None', None),
PythonFunctionArgument('d', PythonArgumentKind.KEYWORD_ONLY, 'False', None),
PythonFunctionArgument('kwargs', PythonArgumentKind.KWARGS, None, None),
]),
(argument_list('a = 1'), [
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '1', None)
]),
])
def test_PythonASTArgumentsListParser_to_argument_list(ast_arguments_list, expected):
assert PythonASTArgumentsListParser(ast_arguments_list).to_argument_list() == expected