From 301af3a6a8476aca812833510eed85e8f3be8748 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Mon, 27 Nov 2023 07:06:45 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Improve:=20represent=20callable?= =?UTF-8?q?=20constants?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/autodoc2/astroid_utils.py | 3 +++ tests/test_analyse_module.py | 2 ++ .../test_basic_assign_class_.yml | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 tests/test_analyse_module/test_basic_assign_class_.yml diff --git a/src/autodoc2/astroid_utils.py b/src/autodoc2/astroid_utils.py index e7d0d76..360ec90 100644 --- a/src/autodoc2/astroid_utils.py +++ b/src/autodoc2/astroid_utils.py @@ -109,6 +109,9 @@ def get_const_values(node: nodes.NodeNG) -> t.Any: value = tuple(new_value) elif isinstance(node, nodes.Const): value = node.value + elif isinstance(node, nodes.Call): + # TODO represent also the arguments + value = f"{node.func.repr_name()}(...)" return value diff --git a/tests/test_analyse_module.py b/tests/test_analyse_module.py index 81231c0..c6e1d56 100644 --- a/tests/test_analyse_module.py +++ b/tests/test_analyse_module.py @@ -23,6 +23,8 @@ def clean_item(item: dict[str, t.Any]) -> dict[str, t.Any]: # annotation only assign "assign_annotation": "a: str", "assign_annotation_union": "a: str | int", + # assign + "assign_class": "class Foo: ...\na = Foo()", # assign with annotation "assign_string": "a: str = 'Hello World'\n'''Docstring'''", "assign_bytes": "a: bytes = b'Hello World'", diff --git a/tests/test_analyse_module/test_basic_assign_class_.yml b/tests/test_analyse_module/test_basic_assign_class_.yml new file mode 100644 index 0000000..bfdc307 --- /dev/null +++ b/tests/test_analyse_module/test_basic_assign_class_.yml @@ -0,0 +1,19 @@ +- all: null + doc: '' + full_name: test + type: module +- bases: [] + doc: '' + full_name: test.Foo + range: + - 1 + - 1 + type: class +- annotation: null + doc: '' + full_name: test.a + range: + - 2 + - 2 + type: data + value: Foo(...)