### Problem With current master version of the `autodoc` extension, a *undocumented* module level attribute preceding a class leaks in the class documentation. #### Procedure to reproduce the problem The following snippet: ```python import logging logger = getLogger(__name__) class Foo(object): "Bar" ``` will result in a `Foo` class having a `logger` data member with a `None` value. ##### Test case I added the following test in `tests/test_pycode.py`: ```python def test_ModuleAnalyzer_spurious_attr(): code = ('import logging\n\n' 'logger = logging.getLogger(__name__)\n\n' 'class Foo(object):\n' ' """Bar"""\n') analyzer = ModuleAnalyzer.for_string(code, 'module') docs = analyzer.find_attr_docs() assert set(docs) == {} ``` ##### Error logs / results When I execute `python run.py test_pycode.py` I get the following: ``` test_pycode.py .....F ========================== FAILURES =========================== ______________ test_ModuleAnalyzer_spurious_attr ______________ def test_ModuleAnalyzer_spurious_attr(): code = ('import logging\n\n' 'logger = logging.getLogger(__name__)\n\n' 'class Foo(object):\n' ' """Bar"""\n') analyzer = ModuleAnalyzer.for_string(code, 'module') docs = analyzer.find_attr_docs() > assert set(docs) == {} E AssertionError: assert {('Foo', 'logger')} == {} E Use -v to get the full diff test_pycode.py:165: AssertionError ============= 1 failed, 5 passed in 0.06 seconds ============== ``` ### Environment info - OS: Debian GNU/Linux sid - Python version: Python 3.6.3 - Sphinx version: current master, commit c39459ea7a894128ce72644ad6dc06ebb78988e7
Activity
Fix sphinx-doc#4156: failed to parse class comment
Fix sphinx-doc#4156: failed to parse class comment
Merge pull request #4157 from tk0miya/4156_parse_class_comment