Skip to content

Commit 4428fe0

Browse files
committed
Fix typedefed anonymous enumerations being documneted twice.
When an enumeration was contained in a typedef it was being documented once as the type and once as anonymous. this has been resolved to only be documented as the typedef. For example the following: typedef enum { SOME_ENUM_0, SOME_ENUM_1, } the_typedef_name; Used to show up as: enum the_typedef_name SOME_ENUM_0 SOME_ENUM_1 enum anon_<file>_<######> SOME_ENUM_0 SOME_ENUM_1
1 parent 4a2bef5 commit 4428fe0

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ This project adheres to `Semantic Versioning <https://semver.org/>`_.
99
`v0.2.0-dev`_ (unreleased)
1010
==========================
1111

12+
Fixes
13+
-----
14+
15+
* Anonymous enumerations which were contained in a typedef were being documented twice.
16+
Once as the typedef and once as anonymous. Now they are only documnted as
17+
part of the typedef.
18+
1219
`v0.1.1`_ (2012-03-15)
1320
======================
1421

mypy.ini

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@ ignore_missing_imports = True
88
ignore_missing_imports = True
99

1010
[mypy-bs4.*]
11-
ignore_missing_imports = True
12-
13-
[mypy-test*]
14-
ignore_errors = True
11+
ignore_missing_imports = True

src/sphinx_c_autodoc/loader.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,11 @@ def object_from_cursor(cursor: Cursor) -> Optional[DocumentedObject]:
542542
name = cursor.spelling
543543

544544
if not name:
545-
if cursor.kind in ALLOWED_ANONYMOUS:
545+
# An anonymous construct which isn't contained in a typedef will have a
546+
# type spelling of:
547+
# "<construct> (anonymous at # <path_to_c_file>:<lineno>)"
548+
# Typedef's should be handled by the get_nested_node() function
549+
if cursor.kind in ALLOWED_ANONYMOUS and "anonymous at" in cursor.type.spelling:
546550
filename = os.path.basename(cursor.location.file.name)
547551
# remove the extension from the filename since the '.' is not a
548552
# valid c identifier. splitext will remove the trailing most

tests/sphinx_project/test_sphinx_build.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
For all of these tests warnigns are treated as errors so that any warnings
55
from bad logic can more easily be seen in the test output
66
"""
7+
import re
78
import os
89
import shutil
910
from sphinx.cmd.build import main
@@ -27,6 +28,12 @@ def test_autodoc_of_c_file(tmp_path):
2728
# Check for anonymouse enumerations
2829
assert 'anon_example_' in contents
2930

31+
# Check for a bug where typedefed enums showed up as anonymouse and the
32+
# typedef.
33+
occurences = len(re.findall("THE_LAST_ENUM", contents))
34+
occurences //= 2 # The text and the anchor.
35+
assert occurences == 1
36+
3037
file_name = tmp_path / "sub_dir" / 'file_2.html'
3138
with file_name.open() as f:
3239
contents = f.read()

0 commit comments

Comments
 (0)