Autosummary issue with aliased names

Open
#11,031 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
documentation

Research direction

Reproduce the issue with the example_bug/init.py, example_bug/_impl.py, source/index.rst, and source/conf.py files using the shown sphinx-build command. Start with the autosummary extension's handling of the aliased Foo class and its uninitialized bar attribute. Done means the build no longer warns about Foo.bar and both attributes are documented.

Written by the indexing model from the issue text.

Description

extensions:autosummary type:bug
Describe the bug

Sphinx fails to resolve class attributes when they do not have a default, and when the class that they belong to have been aliased (e.g. by changing the class' __module__ attribute). It correctly resolves the attribute when it has a value.

How to Reproduce

Minimal method:

$ tree .
.
├── example_bug
│   ├── _impl.py
│   └── __init__.py
└── source
    ├── conf.py
    └── index.rst

index.rst:

Test
====

.. autosummary::
   :toctree: api

   example_bug.Foo

conf.py:

project = 'autosummary-bug'

extensions = ['sphinx.ext.autosummary']

The code to document:

example_bug/__init__.py:

from ._impl import Foo

Foo.__module__ =__name__

example_bug/_impl.py:

class Foo:
    bar: int
    foo: float = 3.14

The problem:

PYTHONPATH=$(pwd) sphinx-build source/ build/html/ -W --keep-going

Running Sphinx v6.0.0b3+/d8977d3e5
making output directory... done
[autosummary] generating autosummary for: index.rst
[autosummary] generating autosummary for: source/api/example_bug.Foo.rst
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 1 source files that are out of date
updating environment: [new config] 2 added, 0 changed, 0 removed
reading sources... [100%] index                                                                                                                                                                                                                    
source/api/example_bug.Foo.rst:24: WARNING: autosummary: failed to import Foo.bar.
Possible hints:
* KeyError: 'Foo'
* ImportError: 
* AttributeError: type object 'Foo' has no attribute 'Foo'
* AttributeError: type object 'Foo' has no attribute 'bar'
* ModuleNotFoundError: No module named 'example_bug.Foo'
* ModuleNotFoundError: No module named 'Foo'
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index                                                                                                                                                                                                                     
generating indices... genindex done
writing additional pages... search done
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build finished with problems, 1 warning.

Notice that Foo.bar is not documented, but Foo.foo is.

Environment Information
Platform:              linux; (Linux-5.4.0-135-generic-x86_64-with-glibc2.31)
Python version:        3.9.7 (default, Sep 16 2021, 13:09:58) 
[GCC 7.5.0])
Python implementation: CPython
Sphinx version:        6.0.0b3+/d8977d3e5
Docutils version:      0.19
Jinja2 version:        3.1.2
Sphinx extensions

autosummary

Additional context

No response

Dominant language
Python
Stars
8k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sphinx-doc/sphinx

All issues in sphinx-doc/sphinx

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.