diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-04-14 15:43:38 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-04-14 15:43:38 +0900 |
commit | af4647c4927622ee53c7fb1a308d844bfa36bcac (patch) | |
tree | 149587f7f321a208a858be80467d3c67fac770b2 | |
parent | c35eb6fade7a3b4a6de4183d1dd4196f04a5edaf (diff) | |
parent | 72762db255657f25e50dd14560b09e50bd5f0a67 (diff) | |
download | sphinx-git-af4647c4927622ee53c7fb1a308d844bfa36bcac.tar.gz |
Merge branch '1.7'
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | setup.py | 13 | ||||
-rw-r--r-- | sphinx/builders/_epub_base.py | 8 | ||||
-rw-r--r-- | sphinx/directives/other.py | 2 | ||||
-rw-r--r-- | sphinx/pycode/parser.py | 29 | ||||
-rw-r--r-- | sphinx/templates/quickstart/conf.py_t | 2 | ||||
-rw-r--r-- | sphinx/theming.py | 4 | ||||
-rw-r--r-- | sphinx/util/inspect.py | 5 | ||||
-rw-r--r-- | sphinx/writers/html.py | 2 | ||||
-rw-r--r-- | sphinx/writers/html5.py | 2 | ||||
-rw-r--r-- | sphinx/writers/latex.py | 2 | ||||
-rw-r--r-- | sphinx/writers/manpage.py | 2 | ||||
-rw-r--r-- | sphinx/writers/texinfo.py | 2 | ||||
-rw-r--r-- | sphinx/writers/text.py | 2 | ||||
-rw-r--r-- | tests/test_autodoc.py | 5 | ||||
-rw-r--r-- | tests/test_pycode_parser.py | 14 |
16 files changed, 77 insertions, 19 deletions
@@ -99,6 +99,8 @@ Bugs fixed * #4789: imgconverter: confused by convert.exe of Windows * #4783: On windows, Sphinx crashed when drives of srcdir and outdir are different +* #4812: autodoc ignores type annotated variables +* #4817: wrong URLs on warning messages Testing -------- @@ -189,6 +189,9 @@ setup( 'Environment :: Web Environment', 'Intended Audience :: Developers', 'Intended Audience :: Education', + 'Intended Audience :: End Users/Desktop', + 'Intended Audience :: Science/Research', + 'Intended Audience :: System Administrators', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', @@ -200,12 +203,22 @@ setup( 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', + 'Framework :: Setuptools Plugin', 'Framework :: Sphinx', 'Framework :: Sphinx :: Extension', 'Framework :: Sphinx :: Theme', 'Topic :: Documentation', 'Topic :: Documentation :: Sphinx', + 'Topic :: Internet :: WWW/HTTP :: Site Management', + 'Topic :: Printing', + 'Topic :: Software Development', + 'Topic :: Software Development :: Documentation', 'Topic :: Text Processing', + 'Topic :: Text Processing :: General', + 'Topic :: Text Processing :: Indexing', + 'Topic :: Text Processing :: Markup', + 'Topic :: Text Processing :: Markup :: HTML', + 'Topic :: Text Processing :: Markup :: LaTeX', 'Topic :: Utilities', ], platforms='any', diff --git a/sphinx/builders/_epub_base.py b/sphinx/builders/_epub_base.py index 839844055..fe285403b 100644 --- a/sphinx/builders/_epub_base.py +++ b/sphinx/builders/_epub_base.py @@ -708,9 +708,9 @@ class EpubBuilder(StandaloneHTMLBuilder): """ logger.info(__('writing %s file...'), outname) epub_filename = path.join(outdir, outname) - with ZipFile(epub_filename, 'w', ZIP_DEFLATED) as epub: # type: ignore - epub.write(path.join(outdir, 'mimetype'), 'mimetype', ZIP_STORED) # type: ignore + with ZipFile(epub_filename, 'w', ZIP_DEFLATED) as epub: + epub.write(path.join(outdir, 'mimetype'), 'mimetype', ZIP_STORED) for filename in [u'META-INF/container.xml', u'content.opf', u'toc.ncx']: - epub.write(path.join(outdir, filename), filename, ZIP_DEFLATED) # type: ignore + epub.write(path.join(outdir, filename), filename, ZIP_DEFLATED) for filename in self.files: - epub.write(path.join(outdir, filename), filename, ZIP_DEFLATED) # type: ignore + epub.write(path.join(outdir, filename), filename, ZIP_DEFLATED) diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index 450999435..882f41b92 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -25,7 +25,7 @@ from sphinx.util.nodes import explicit_title_re, set_source_info, \ if False: # For type annotation - from typing import Any, Dict, List, Tuple # NOQA + from typing import Any, Dict, Generator, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py index 8f6615b54..f943b7985 100644 --- a/sphinx/pycode/parser.py +++ b/sphinx/pycode/parser.py @@ -12,6 +12,7 @@ import ast import inspect import itertools import re +import sys import tokenize from token import NAME, NEWLINE, INDENT, DEDENT, NUMBER, OP, STRING from tokenize import COMMENT, NL @@ -27,6 +28,21 @@ indent_re = re.compile(u'^\\s*$') emptyline_re = re.compile(u'^\\s*(#.*)?$') +if sys.version_info >= (3, 6): + ASSIGN_NODES = (ast.Assign, ast.AnnAssign) +else: + ASSIGN_NODES = (ast.Assign) + + +def get_assign_targets(node): + # type: (ast.AST) -> List[ast.expr] + """Get list of targets from Assign and AnnAssign node.""" + if isinstance(node, ast.Assign): + return node.targets + else: + return [node.target] # type: ignore + + def get_lvar_names(node, self=None): # type: (ast.AST, ast.expr) -> List[unicode] """Convert assignment-AST to variable names. @@ -285,7 +301,8 @@ class VariableCommentPicker(ast.NodeVisitor): # type: (ast.Assign) -> None """Handles Assign node and pick up a variable comment.""" try: - varnames = sum([get_lvar_names(t, self=self.get_self()) for t in node.targets], []) + targets = get_assign_targets(node) + varnames = sum([get_lvar_names(t, self=self.get_self()) for t in targets], []) current_line = self.get_line(node.lineno) except TypeError: return # this assignment is not new definition! @@ -321,12 +338,18 @@ class VariableCommentPicker(ast.NodeVisitor): for varname in varnames: self.add_entry(varname) + def visit_AnnAssign(self, node): + # type: (ast.AST) -> None + """Handles AnnAssign node and pick up a variable comment.""" + self.visit_Assign(node) # type: ignore + def visit_Expr(self, node): # type: (ast.Expr) -> None """Handles Expr node and pick up a comment if string.""" - if (isinstance(self.previous, ast.Assign) and isinstance(node.value, ast.Str)): + if (isinstance(self.previous, ASSIGN_NODES) and isinstance(node.value, ast.Str)): try: - varnames = get_lvar_names(self.previous.targets[0], self.get_self()) + targets = get_assign_targets(self.previous) + varnames = get_lvar_names(targets[0], self.get_self()) for varname in varnames: if isinstance(node.value.s, text_type): docstring = node.value.s diff --git a/sphinx/templates/quickstart/conf.py_t b/sphinx/templates/quickstart/conf.py_t index 2f3f71b1e..6a648f39c 100644 --- a/sphinx/templates/quickstart/conf.py_t +++ b/sphinx/templates/quickstart/conf.py_t @@ -4,7 +4,7 @@ # # This file does only contain a selection of the most common options. For a # full list see the documentation: -# http://www.sphinx-doc.org/en/stable/config +# http://www.sphinx-doc.org/en/master/config # -- Path setup -------------------------------------------------------------- diff --git a/sphinx/theming.py b/sphinx/theming.py index 7287f7fc4..944c446c3 100644 --- a/sphinx/theming.py +++ b/sphinx/theming.py @@ -43,7 +43,7 @@ def extract_zip(filename, targetdir): """Extract zip file to target directory.""" ensuredir(targetdir) - with ZipFile(filename) as archive: # type: ignore + with ZipFile(filename) as archive: for name in archive.namelist(): if name.endswith('/'): continue @@ -155,7 +155,7 @@ def is_archived_theme(filename): # type: (unicode) -> bool """Check the specified file is an archived theme file or not.""" try: - with ZipFile(filename) as f: # type: ignore + with ZipFile(filename) as f: return THEMECONF in f.namelist() except Exception: return False diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 6b404790c..5bac708f3 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -313,7 +313,10 @@ class Signature(object): try: self.signature = inspect.signature(subject) except IndexError: - if hasattr(subject, '_partialmethod'): # partialmethod with no argument + # Until python 3.6.4, cpython has been crashed on inspection for + # partialmethods not having any arguments. + # https://bugs.python.org/issue33009 + if hasattr(subject, '_partialmethod'): self.signature = None self.partialmethod_with_noargs = True else: diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index 9e737bb2c..0586636df 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -876,7 +876,7 @@ class HTMLTranslator(BaseTranslator): # type: (nodes.Node, unicode) -> None logger.warning(__('using "math" markup without a Sphinx math extension ' 'active, please use one of the math extensions ' - 'described at http://sphinx-doc.org/ext/math.html'), + 'described at http://sphinx-doc.org/en/master/ext/math.html'), location=(self.builder.current_docname, node.line)) raise nodes.SkipNode diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index 420822c32..85a7ef7c2 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -827,7 +827,7 @@ class HTML5Translator(BaseTranslator): # type: (nodes.Node, unicode) -> None logger.warning(__('using "math" markup without a Sphinx math extension ' 'active, please use one of the math extensions ' - 'described at http://sphinx-doc.org/ext/math.html'), + 'described at http://sphinx-doc.org/en/master/ext/math.html'), location=(self.builder.current_docname, node.line)) raise nodes.SkipNode diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 3a35a06e6..68acc8e9a 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -2635,7 +2635,7 @@ class LaTeXTranslator(nodes.NodeVisitor): # type: (nodes.Node) -> None logger.warning(__('using "math" markup without a Sphinx math extension ' 'active, please use one of the math extensions ' - 'described at http://sphinx-doc.org/ext/math.html'), + 'described at http://sphinx-doc.org/en/master/ext/math.html'), location=(self.curfilestack[-1], node.line)) raise nodes.SkipNode diff --git a/sphinx/writers/manpage.py b/sphinx/writers/manpage.py index 76884cbf6..c6c8723dd 100644 --- a/sphinx/writers/manpage.py +++ b/sphinx/writers/manpage.py @@ -515,7 +515,7 @@ class ManualPageTranslator(BaseTranslator): # type: (nodes.Node) -> None logger.warning(__('using "math" markup without a Sphinx math extension ' 'active, please use one of the math extensions ' - 'described at http://sphinx-doc.org/ext/math.html')) + 'described at http://sphinx-doc.org/en/master/ext/math.html')) raise nodes.SkipNode visit_math_block = visit_math diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index 36c48131f..c24ba60bd 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -1745,7 +1745,7 @@ class TexinfoTranslator(nodes.NodeVisitor): # type: (nodes.Node) -> None logger.warning(__('using "math" markup without a Sphinx math extension ' 'active, please use one of the math extensions ' - 'described at http://sphinx-doc.org/ext/math.html')) + 'described at http://sphinx-doc.org/en/master/ext/math.html')) raise nodes.SkipNode visit_math_block = visit_math diff --git a/sphinx/writers/text.py b/sphinx/writers/text.py index 79789fcca..2bc43a30d 100644 --- a/sphinx/writers/text.py +++ b/sphinx/writers/text.py @@ -1185,7 +1185,7 @@ class TextTranslator(nodes.NodeVisitor): # type: (nodes.Node) -> None logger.warning(__('using "math" markup without a Sphinx math extension ' 'active, please use one of the math extensions ' - 'described at http://sphinx-doc.org/ext/math.html'), + 'described at http://sphinx-doc.org/en/master/ext/math.html'), location=(self.builder.current_docname, node.line)) raise nodes.SkipNode diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index 9398edc34..ed6d050fa 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -952,7 +952,10 @@ def test_partialmethod(): ' Update state of cell to *state*.', ' ', ] - if sys.version_info < (3, 5, 4): + if (sys.version_info < (3, 5, 4) or + (3, 6, 5) <= sys.version_info < (3, 7) or + (3, 7, 0, 'beta', 3) <= sys.version_info): + # TODO: this condition should be updated after 3.7-final release. expected = '\n'.join(expected).replace(' -> None', '').split('\n') assert call_autodoc('class', 'target.partialmethod.Cell') == expected diff --git a/tests/test_pycode_parser.py b/tests/test_pycode_parser.py index b9327999b..09f1f41f5 100644 --- a/tests/test_pycode_parser.py +++ b/tests/test_pycode_parser.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +import sys + import pytest from six import PY2 @@ -94,6 +96,18 @@ def test_comment_picker_location(): ('Foo', 'attr3'): 'comment for attr3(3)'} +@pytest.mark.skipif(sys.version_info < (3, 6), reason='tests for py36+ syntax') +def test_annotated_assignment_py36(): + source = ('a: str = "Sphinx" #: comment\n' + 'b: int = 1\n' + '"""string on next line"""') + parser = Parser(source) + parser.parse() + assert parser.comments == {('', 'a'): 'comment', + ('', 'b'): 'string on next line'} + assert parser.definitions == {} + + def test_complex_assignment(): source = ('a = 1 + 1; b = a #: compound statement\n' 'c, d = (1, 1) #: unpack assignment\n' |