diff --git a/CHANGES b/CHANGES index 9eceac076..d5d0026fa 100644 --- a/CHANGES +++ b/CHANGES @@ -195,6 +195,7 @@ Bugs fixed * #1922: html search: Upper characters problem in French * #4412: Updated jQuery version from 3.1.0 to 3.2.1 * #4438: math: math with labels with whitespace cause html error +* #2437: make full reference for classes, aliased with "alias of" Testing -------- diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 1597d0c1b..669074bae 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1158,8 +1158,14 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type: def add_content(self, more_content, no_docstring=False): # type: (Any, bool) -> None if self.doc_as_attr: - classname = safe_getattr(self.object, '__name__', None) + classname = safe_getattr(self.object, '__qualname__', None) + if not classname: + classname = safe_getattr(self.object, '__name__', None) if classname: + module = safe_getattr(self.object, '__module__', None) + parentmodule = safe_getattr(self.parent, '__module__', None) + if module and module != parentmodule: + classname = str(module) + u'.' + str(classname) content = ViewList( [_('alias of :class:`%s`') % classname], source='') ModuleLevelDocumenter.add_content(self, content, diff --git a/sphinx/ext/mathbase.py b/sphinx/ext/mathbase.py index d9bc3726b..f773c0d24 100644 --- a/sphinx/ext/mathbase.py +++ b/sphinx/ext/mathbase.py @@ -56,8 +56,7 @@ class MathDomain(Domain): label = 'mathematics' initial_data = { - 'nameids': {}, # label -> equation ID - 'objects': {}, # equation ID -> (docname, eqno) + 'objects': {}, # labelid -> (docname, eqno) } # type: Dict[unicode, Dict[unicode, Tuple[unicode, int]]] dangling_warnings = { 'eq': 'equation not found: %(target)s', diff --git a/sphinx/io.py b/sphinx/io.py index 7044ab3c0..d85b6c483 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -80,7 +80,6 @@ class SphinxBaseReader(standalone.Reader): # substitute reporter reporter = document.reporter document.reporter = LoggingReporter.from_reporter(reporter) - document.reporter.set_source(self.source) return document diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py index bfaff758f..2848bc857 100644 --- a/sphinx/util/docutils.py +++ b/sphinx/util/docutils.py @@ -18,7 +18,7 @@ from contextlib import contextmanager import docutils from docutils.languages import get_language -from docutils.statemachine import StateMachine, ViewList +from docutils.statemachine import StateMachine from docutils.parsers.rst import directives, roles, convert_directive_function from docutils.utils import Reporter @@ -33,7 +33,7 @@ if False: # For type annotation from typing import Any, Callable, Generator, Iterator, List, Tuple # NOQA from docutils import nodes # NOQA - from docutils.statemachine import State # NOQA + from docutils.statemachine import State, ViewList # NOQA from sphinx.environment import BuildEnvironment # NOQA from sphinx.io import SphinxFileInput # NOQA @@ -183,21 +183,6 @@ class LoggingReporter(Reporter): stream = WarningStream() Reporter.__init__(self, source, report_level, halt_level, stream, debug, error_handler=error_handler) - self.source_and_line = None # type: SphinxFileInput - - def set_source(self, source): - # type: (SphinxFileInput) -> None - self.source_and_line = source - - def system_message(self, *args, **kwargs): - # type: (Any, Any) -> Any - if kwargs.get('line') and isinstance(self.source_and_line, ViewList): - # replace source parameter if source is set - source, lineno = self.source_and_line.info(kwargs.get('line')) - kwargs['source'] = source - kwargs['line'] = lineno - - return Reporter.system_message(self, *args, **kwargs) def is_html5_writer_available(): diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 3139a43ad..e2a10f391 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1512,8 +1512,6 @@ class LaTeXTranslator(nodes.NodeVisitor): context = ('\\par\n\\vskip-\\baselineskip' '\\vbox{\\hbox{\\strut}}\\end{varwidth}%\n') + context self.needs_linetrimming = 1 - if len(node) > 2 and len(node.astext().split('\n')) > 2: - self.needs_linetrimming = 1 if len(node.traverse(nodes.paragraph)) >= 2: self.table.has_oldproblematic = True if isinstance(node.parent.parent, nodes.thead) or (cell.col in self.table.stubs): diff --git a/tests/roots/test-ext-autodoc/autodoc_dummy_bar.py b/tests/roots/test-ext-autodoc/autodoc_dummy_bar.py new file mode 100644 index 000000000..d79d1691f --- /dev/null +++ b/tests/roots/test-ext-autodoc/autodoc_dummy_bar.py @@ -0,0 +1,5 @@ +from bug2437.autodoc_dummy_foo import Foo + +class Bar(object): + """Dummy class Bar with alias.""" + my_name = Foo diff --git a/tests/roots/test-ext-autodoc/bug2437/__init__.py b/tests/roots/test-ext-autodoc/bug2437/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/roots/test-ext-autodoc/bug2437/autodoc_dummy_foo.py b/tests/roots/test-ext-autodoc/bug2437/autodoc_dummy_foo.py new file mode 100644 index 000000000..b578a2255 --- /dev/null +++ b/tests/roots/test-ext-autodoc/bug2437/autodoc_dummy_foo.py @@ -0,0 +1,3 @@ +class Foo(object): + """Dummy class Foo.""" + pass diff --git a/tests/roots/test-ext-autodoc/conf.py b/tests/roots/test-ext-autodoc/conf.py index 01e6dcc75..9f026eb8d 100644 --- a/tests/roots/test-ext-autodoc/conf.py +++ b/tests/roots/test-ext-autodoc/conf.py @@ -10,3 +10,5 @@ source_suffix = '.rst' autodoc_mock_imports = [ 'dummy' ] + +nitpicky = True diff --git a/tests/roots/test-ext-autodoc/contents.rst b/tests/roots/test-ext-autodoc/contents.rst index b808eafda..ce4302204 100644 --- a/tests/roots/test-ext-autodoc/contents.rst +++ b/tests/roots/test-ext-autodoc/contents.rst @@ -1,3 +1,9 @@ .. automodule:: autodoc_dummy_module :members: + +.. automodule:: bug2437.autodoc_dummy_foo + :members: + +.. automodule:: autodoc_dummy_bar + :members: diff --git a/tests/roots/test-latex-table/expects/table_having_threeparagraphs_cell_in_first_col.tex b/tests/roots/test-latex-table/expects/table_having_threeparagraphs_cell_in_first_col.tex new file mode 100644 index 000000000..20d949493 --- /dev/null +++ b/tests/roots/test-latex-table/expects/table_having_threeparagraphs_cell_in_first_col.tex @@ -0,0 +1,20 @@ +\label{\detokenize{tabular:table-with-cell-in-first-column-having-three-paragraphs}} + +\begin{savenotes}\sphinxattablestart +\centering +\begin{tabulary}{\linewidth}[t]{|T|} +\hline +\sphinxstyletheadfamily +header1 +\\ +\hline +cell1-1-par1 + +cell1-1-par2 + +cell1-1-par3 +\\ +\hline +\end{tabulary} +\par +\sphinxattableend\end{savenotes} diff --git a/tests/roots/test-latex-table/tabular.rst b/tests/roots/test-latex-table/tabular.rst index 24091a3e1..b28add3d3 100644 --- a/tests/roots/test-latex-table/tabular.rst +++ b/tests/roots/test-latex-table/tabular.rst @@ -68,6 +68,20 @@ cell2-1 cell2-2 cell3-1 cell3-2 ======= ======= +table with cell in first column having three paragraphs +------------------------------------------------------- + ++--------------+ +| header1 | ++==============+ +| cell1-1-par1 | +| | +| cell1-1-par2 | +| | +| cell1-1-par3 | ++--------------+ + + table having caption -------------------- diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index e7b61ad0c..d1d84ce4e 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -943,7 +943,7 @@ def test_maxlistdepth_at_ten(app, status, warning): @pytest.mark.skipif(docutils.__version_info__ < (0, 13), reason='docutils-0.13 or above is required') @pytest.mark.sphinx('latex', testroot='latex-table') -@pytest.mark.test_params(shared_result='test_latex_table') +@pytest.mark.test_params(shared_result='latex-table') def test_latex_table_tabulars(app, status, warning): app.builder.build_all() result = (app.outdir / 'test.tex').text(encoding='utf8') @@ -980,6 +980,11 @@ def test_latex_table_tabulars(app, status, warning): expected = get_expected('tabularcolumn') assert actual == expected + # table with cell in first column having three paragraphs + actual = tables['table with cell in first column having three paragraphs'] + expected = get_expected('table_having_threeparagraphs_cell_in_first_col') + assert actual == expected + # table having caption actual = tables['table having caption'] expected = get_expected('table_having_caption') @@ -1009,7 +1014,7 @@ def test_latex_table_tabulars(app, status, warning): @pytest.mark.skipif(docutils.__version_info__ < (0, 13), reason='docutils-0.13 or above is required') @pytest.mark.sphinx('latex', testroot='latex-table') -@pytest.mark.test_params(shared_result='test_latex_table') +@pytest.mark.test_params(shared_result='latex-table') def test_latex_table_longtable(app, status, warning): app.builder.build_all() result = (app.outdir / 'test.tex').text(encoding='utf8') @@ -1070,7 +1075,7 @@ def test_latex_table_longtable(app, status, warning): @pytest.mark.skipif(docutils.__version_info__ < (0, 13), reason='docutils-0.13 or above is required') @pytest.mark.sphinx('latex', testroot='latex-table') -@pytest.mark.test_params(shared_result='test_latex_table') +@pytest.mark.test_params(shared_result='latex-table') def test_latex_table_complex_tables(app, status, warning): app.builder.build_all() result = (app.outdir / 'test.tex').text(encoding='utf8') diff --git a/tests/test_ext_autodoc.py b/tests/test_ext_autodoc.py index e7057df0f..7a9666792 100644 --- a/tests/test_ext_autodoc.py +++ b/tests/test_ext_autodoc.py @@ -22,3 +22,13 @@ def test_autodoc(app, status, warning): assert isinstance(content[3], addnodes.desc) assert content[3][0].astext() == 'autodoc_dummy_module.test' assert content[3][1].astext() == 'Dummy function using dummy.*' + + # issue sphinx-doc/sphinx#2437 + assert content[11][-1].astext() == """Dummy class Bar with alias. + + + +my_name + +alias of bug2437.autodoc_dummy_foo.Foo""" + assert warning.getvalue() == ''