Correctly render tuples as tuples, not lists

Fixes #330
pull/362/head
Ashley Whetter 2 years ago
parent bf7bb08ef8
commit 847b6e5626

@ -3,6 +3,15 @@ Changelog
Versions follow `Semantic Versioning <https://semver.org/>`_ (``<major>.<minor>.<patch>``).
v2.0.1 (TBC)
------------
Bug Fixes
^^^^^^^^^
* `#330 <https://github.com/readthedocs/sphinx-autoapi/issues/330>`: (Python)
Render tuple values as tuples, not lists.
v2.0.0 (2022-09-27)
-------------------

@ -139,6 +139,9 @@ def _get_const_values(node):
break
else:
value = new_value
if isinstance(node, astroid.nodes.Tuple):
value = tuple(new_value)
elif isinstance(node, astroid.nodes.Const):
value = node.value

@ -4,6 +4,11 @@
This is a description
"""
A_TUPLE = ("a", "b")
"""A tuple to be rendered as a tuple."""
A_LIST = ["c", "d"]
"""A list to be rendered as a list."""
class Foo(object):
"""Can we parse arguments from the class docstring?

@ -104,6 +104,11 @@ class TestSimpleModule:
# (autoapi_python_class_content="both") class docstring only once.
assert example_file.count("One __init__.") == 3
# Tuples should be rendered as tuples, not lists
assert "('a', 'b')" in example_file
# Lists should be rendered as lists, not tuples
assert "['c', 'd']" in example_file
index_path = "_build/text/index.txt"
with io.open(index_path, encoding="utf8") as index_handle:
index_file = index_handle.read()

Loading…
Cancel
Save