From b1c100ca3b038f930bb55853c96ee29c782d2015 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 24 Oct 2017 13:26:32 +0300 Subject: [PATCH 1/3] autodoc: make full reference for classes, aliased with "alias of" We do this here only if class belongs to the different module. Closes sphinx-doc/sphinx#2437 --- CHANGES | 2 ++ sphinx/ext/autodoc.py | 8 +++++++- tests/roots/test-ext-autodoc/autodoc_dummy_bar.py | 5 +++++ tests/roots/test-ext-autodoc/bug2437/__init__.py | 0 .../test-ext-autodoc/bug2437/autodoc_dummy_foo.py | 3 +++ tests/roots/test-ext-autodoc/conf.py | 2 ++ tests/roots/test-ext-autodoc/contents.rst | 6 ++++++ tests/test_ext_autodoc.py | 10 ++++++++++ 8 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/roots/test-ext-autodoc/autodoc_dummy_bar.py create mode 100644 tests/roots/test-ext-autodoc/bug2437/__init__.py create mode 100644 tests/roots/test-ext-autodoc/bug2437/autodoc_dummy_foo.py diff --git a/CHANGES b/CHANGES index 00fcb59a7..829243356 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ Features added Bugs fixed ---------- +* #2437: make full reference for classes, aliased with "alias of" + Testing -------- diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index bd686644c..1ccd74647 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -1513,8 +1513,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/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/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() == '' From 9aca29a7816c8989a7d67356f270c255cca3c2bb Mon Sep 17 00:00:00 2001 From: jfbu Date: Thu, 18 Jan 2018 14:33:17 +0100 Subject: [PATCH 2/3] Fix "Undefined control sequence \\hlineSomeText" (#4431; refs: #3435) --- sphinx/writers/latex.py | 2 -- ...ving_threeparagraphs_cell_in_first_col.tex | 20 +++++++++++++++++++ tests/roots/test-latex-table/tabular.rst | 14 +++++++++++++ tests/test_build_latex.py | 11 +++++++--- 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 tests/roots/test-latex-table/expects/table_having_threeparagraphs_cell_in_first_col.tex diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 98fec811c..7791d4aa6 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1477,8 +1477,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-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..7e21181f8 --- /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 +\sphinxstylethead{\sphinxstyletheadfamily +header1 +\unskip}\relax \\ +\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 0c95a0cdb..1ba115092 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -877,7 +877,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') @@ -914,6 +914,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') @@ -943,7 +948,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') @@ -1004,7 +1009,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') From 20a6cb624079d02d96d49d1884b615f1eb92e4ec Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 20 Jan 2018 02:24:34 +0900 Subject: [PATCH 3/3] mathbase: Remove unused data --- sphinx/ext/mathbase.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sphinx/ext/mathbase.py b/sphinx/ext/mathbase.py index 8370c923e..8372c3ddd 100644 --- a/sphinx/ext/mathbase.py +++ b/sphinx/ext/mathbase.py @@ -52,8 +52,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',