Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sphinx: "WARNING: py:class reference target not found" for class variable

I have two files, foo.py and bar.py.

foo.py contains:

import bar


class B():
    a = bar.A

bar.py contains:

class A():
    pass

I am generating documentation for these in docs/index.rst via:

.. automodule:: bar
   :members:
   :undoc-members:

.. automodule:: foo
   :members:
   :undoc-members:

Now, when I run build html with the nit-picky flag (-n), I get the following, with a warning, WARNING: py:class reference target not found: A:

(env)bash-3.2$ make html
sphinx-build -b html -d _build/doctrees  -n . _build/html
Running Sphinx v1.2.3
loading pickled environment... done
building [html]: targets for 1 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
reading sources... [100%] index
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index
/Users/caesarbautista/Desktop/test_docs/docs/index.rst:12: WARNING: py:class reference target not found: A
writing additional files... genindex py-modindex search
copying static files... done
copying extra files... done
dumping search index... done
dumping object inventory... done
build succeeded, 1 warning.

Build finished. The HTML pages are in _build/html.

How can I fix this warning?

So far I've tried searching Google and the documentation with no luck. It also has nothing to do with with how A is imported. I've tried from bar import A with no success. The error message is awfully opaque.

A copy of the test project I set up can be found here.

like image 779
Ceasar Bautista Avatar asked Nov 03 '14 19:11

Ceasar Bautista


1 Answers

In your code you had

class B():
    a = bar.A

You must use an instantiation instead of a class alias. The warning just disappear when I replace a = bar.A with a = bar.A()

like image 136
nino_701 Avatar answered Oct 24 '22 03:10

nino_701