Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Failed to import" error if a class is imported and it has an attribute without a default value #41

Open
xuhdev opened this issue Jan 3, 2021 · 2 comments

Comments

@xuhdev
Copy link

xuhdev commented Jan 3, 2021

Consider a class that has an attribute without a default value, and is imported. If autoclass is applied to this class and autosummary is turned on, sphinx-build errors out.

Reproduce

Download
bug.tar.gz. Unarchive it, and run

PYTHONPATH=. sphinx-build -v -d "./_build" docs "_build/html" -b html -W --color

It produces an error:

Running Sphinx v3.4.1
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] 1 added, 0 changed, 0 removed
reading sources... [100%] index


Traceback (most recent call last):
  File "/home/hong/.local/lib/python3.7/site-packages/sphinx/cmd/build.py", line 280, in build_main
    app.build(args.force_all, filenames)
  File "/home/hong/.local/lib/python3.7/site-packages/sphinx/application.py", line 352, in build
    self.builder.build_update()
  File "/home/hong/.local/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 298, in build_update
    len(to_build))
  File "/home/hong/.local/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 310, in build
    updated_docnames = set(self.read())
  File "/usr/lib/python3.7/contextlib.py", line 119, in __exit__
    next(self.gen)
  File "/home/hong/.local/lib/python3.7/site-packages/sphinx/util/logging.py", line 214, in pending_warnings
    memhandler.flushTo(logger)
  File "/home/hong/.local/lib/python3.7/site-packages/sphinx/util/logging.py", line 179, in flushTo
    logger.handle(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 1529, in handle
    self.callHandlers(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 1591, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 901, in handle
    rv = self.filter(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 762, in filter
    result = f.filter(record)
  File "/home/hong/.local/lib/python3.7/site-packages/sphinx/util/logging.py", line 422, in filter
    raise exc
sphinx.errors.SphinxWarning: /home/hong/tmp/myproject/_impl.py:docstring of myproject._impl.A.rst:1:autosummary: failed to import myproject.A.a

Warning, treated as error:
/home/hong/tmp/myproject/_impl.py:docstring of myproject._impl.A.rst:1:autosummary: failed to import myproject.A.a

Content of bug.tar.gz:

├── docs
│   ├── conf.py
│   └── index.rst
└── myproject
    ├── _impl.py
    └── __init__.py

_impl.py:

class A:
    "A's doc"

    a: int
    "a's doc."

__init__.py:

from ._impl import A

conf.py:

project = 'myproject'
copyright = '2020, someone'
author = 'someone'
extensions = [
    'sphinx.ext.autodoc',
    'autodocsumm'
]
html_theme = 'alabaster'

index.rst:

Welcome to myproject's documentation!
=====================================

.. currentmodule:: myproject

.. autoclass:: A
   :members:
   :show-inheritance:
   :autosummary:

Either removing :autosummary: or put the definition of class A to __init__.py resolves the error.

@Chilipp
Copy link
Owner

Chilipp commented Jan 3, 2021

Hey @xuhdev ! Thanks a lot for reporting this issue. I think that this should rather be resolved within the autosummary extension, shouldn't it? I saw that you already created the corresponding issue in the sphinx repo, so maybe we keep this issue here open and close it when sphinx-doc/sphinx#8645 has been resolved

@xuhdev
Copy link
Author

xuhdev commented Jan 3, 2021

Hi @Chilipp ! I'm not sure whether the two issues are actually the same issue: sphinx-doc/sphinx#8645 doesn't involve imported module, but this issue is only reproduceable if an imported module is involved. But they may be related though, I just don't understand the extension enough to make the judgment.

xuhdev added a commit to xuhdev/poorconn that referenced this issue May 31, 2021
Cause errors such as:

```
poorconn/poorconn/_pytest_plugin.py:docstring of poorconn._pytest_plugin.Server.rst:1:autosummary: failed to import poorconn.pytest_plugin.Server.url
```

in !49.

See Chilipp/autodocsumm#41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants