diff --git a/CHANGES b/CHANGES index f65b0b07a..cc4455050 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ Features added Bugs fixed ---------- +* #10456: filter_meta_fields fails to remove more than one meta-field + Testing -------- diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 8fc185325..a634a51d2 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -1068,11 +1068,11 @@ def filter_meta_fields(app: Sphinx, domain: str, objtype: str, content: Element) for node in content: if isinstance(node, nodes.field_list): fields = cast(List[nodes.field], node) - for field in fields: + # removing list items while iterating the list needs reversed() + for field in reversed(fields): field_name = cast(nodes.field_body, field[0]).astext().strip() if field_name == 'meta' or field_name.startswith('meta '): node.remove(field) - break class PythonModuleIndex(Index): diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py index 61f595c23..014067e84 100644 --- a/tests/test_domain_py.py +++ b/tests/test_domain_py.py @@ -999,7 +999,9 @@ def test_info_field_list(app): text = (".. py:module:: example\n" ".. py:class:: Class\n" "\n" + " :meta blah: this meta-field must not show up in the toc-tree\n" " :param str name: blah blah\n" + " :meta another meta field:\n" " :param age: blah blah\n" " :type age: int\n" " :param items: blah blah\n"