Skip to content

Extraneous class attribute #4156

Closed
Closed

Description

@lelit

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:

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:

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 c39459e

Activity

  1. added a commit that references this issue on Oct 16, 2017
    c4d3b5f
  2. added this to the 1.7 milestone on Oct 16, 2017
  3. added a commit that references this issue on Oct 19, 2017
    7aab8c3
  4. added a commit that references this issue on Oct 21, 2017
    f224f3c
  5. locked as resolved and limited conversation to collaborators on Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions