Skip to content

Commit

Permalink
👌 Improve: represent callable constants (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell authored Nov 27, 2023
1 parent f32d92f commit 2cf0838
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/autodoc2/astroid_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/test_analyse_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down
19 changes: 19 additions & 0 deletions tests/test_analyse_module/test_basic_assign_class_.yml
Original file line number Diff line number Diff line change
@@ -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(...)

0 comments on commit 2cf0838

Please sign in to comment.