Remove core.python.arguments.PythonFunctionArgumentDefault; use strings instead

This commit is contained in:
2026-04-12 18:54:51 +02:00
parent 076e04a67a
commit 73730520c1
2 changed files with 3 additions and 77 deletions
+3 -22
View File
@@ -23,7 +23,6 @@ import types
__all__ = [
'PythonArgumentKind',
'PythonFunctionArgumentDefault',
'PythonFunctionArgument',
'PythonASTArgumentsListParser'
]
@@ -35,24 +34,6 @@ class PythonArgumentKind(Enum):
VARARG = 3
KWARGS = 4
class PythonFunctionArgumentDefault:
'''
Represents the default value of a Python function argument.
:param value: The value
:type value: ast.expr
'''
def __init__(self, value: ast.expr) -> None:
assert_that_is_instance(value, ast.expr)
self.value = value
def __eq__(self, value: PythonFunctionArgumentDefault) -> bool:
if not isinstance(value, PythonFunctionArgumentDefault):
return False
return ast.dump(value.value, include_attributes = False) == ast.dump(self.value, include_attributes = False)
class PythonFunctionArgument:
'''
Represents an argument of a Python function.
@@ -62,15 +43,15 @@ class PythonFunctionArgument:
:param kind: The kind of the argument.
:type kind: ArgumentKind
:param default: The default value of the argument.
:type default: Union[PythonFunctionArgumentDefault, None]
:type default: Union[str, None]
:param annotation: The type annotation of the argument.
:type annotation: Union[str, None]
'''
def __init__(self, name: str, kind: PythonArgumentKind, default: Union[PythonFunctionArgumentDefault, None], annotation: Union[str, None]) -> None:
def __init__(self, name: str, kind: PythonArgumentKind, default: Union[str, None], annotation: Union[str, None]) -> None:
assert_that_is_instance(name, str)
assert_that_is_instance(kind, PythonArgumentKind)
assert_that_is_instance(default, (PythonFunctionArgumentDefault, types.NoneType))
assert_that_is_instance(default, (str, types.NoneType))
assert_that_is_instance(annotation, (str, types.NoneType))
# check whether name is a valid identifier
@@ -1,55 +0,0 @@
# Copyright 2026 jCloud Services GbR
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from src.jcloud_docsgen.core.python.arguments import PythonFunctionArgumentDefault
import pytest
import ast
@pytest.mark.parametrize('default,expected', [
(PythonFunctionArgumentDefault(ast.Constant(value = '')), ast.Constant),
(PythonFunctionArgumentDefault(ast.Constant(value = 'x')), ast.Constant),
(PythonFunctionArgumentDefault(ast.Constant(value = None)), ast.Constant),
(PythonFunctionArgumentDefault(ast.Constant(value = 1)), ast.Constant),
])
def test_PythonFunctionArgumentDefault_value_attribute_type(default, expected):
assert isinstance(default.value, expected)
@pytest.mark.parametrize('value,expected_exception_msg', [
(None, 'expected \'expr\', got \'NoneType\''),
(1, 'expected \'expr\', got \'int\''),
('x', 'expected \'expr\', got \'str\''),
(42, 'expected \'expr\', got \'int\''),
(4.2, 'expected \'expr\', got \'float\''),
])
def test_PythonFunctionArgumentDefault_raises_TypeError(value, expected_exception_msg):
with pytest.raises(TypeError) as exc_info:
PythonFunctionArgumentDefault(value)
assert str(exc_info.value) == expected_exception_msg
@pytest.mark.parametrize('default1,default2,expected', [
(PythonFunctionArgumentDefault(ast.Constant(value = 1)), PythonFunctionArgumentDefault(ast.Constant(value = 1)), True),
(PythonFunctionArgumentDefault(ast.Constant(value = 1)), PythonFunctionArgumentDefault(ast.Constant(value = 2)), False),
(PythonFunctionArgumentDefault(ast.Constant(value = 'a')), PythonFunctionArgumentDefault(ast.Constant(value = 2)), False),
(PythonFunctionArgumentDefault(ast.Constant(value = 'a')), PythonFunctionArgumentDefault(ast.Constant(value = 'a')), True),
(PythonFunctionArgumentDefault(ast.Constant(value = 'a')), PythonFunctionArgumentDefault(ast.Constant(value = 'b')), False),
(PythonFunctionArgumentDefault(ast.List(elts = [])), PythonFunctionArgumentDefault(ast.List(elts = [])), True),
(PythonFunctionArgumentDefault(ast.List(elts = [1])), PythonFunctionArgumentDefault(ast.List(elts = [])), False),
(PythonFunctionArgumentDefault(ast.List(elts = [1])), PythonFunctionArgumentDefault(ast.List(elts = [1])), True),
(PythonFunctionArgumentDefault(ast.List(elts = [1])), PythonFunctionArgumentDefault(ast.List(elts = [2])), False),
(PythonFunctionArgumentDefault(ast.List(elts = [1])), PythonFunctionArgumentDefault(ast.List(elts = [1, 2])), False),
(PythonFunctionArgumentDefault(ast.List(elts = [1, 2])), PythonFunctionArgumentDefault(ast.List(elts = [1, 2])), True),
(PythonFunctionArgumentDefault(ast.List(elts = [2, 1])), PythonFunctionArgumentDefault(ast.List(elts = [1, 2])), False),
])
def test_PythonFunctionArgumentDefault___eq__(default1, default2, expected):
assert (default1 == default2) == expected