summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2018-12-15 22:40:46 +0900
committerGitHub <noreply@github.com>2018-12-15 22:40:46 +0900
commit415ebc15c59e8b2e7fd2eb1df76017a331f8b131 (patch)
tree5934d437249ff312ed5d0fe157d800752fbf796f
parent4d933716b8074eabfa78093bf271908c6d0bc6e6 (diff)
parent77e0139a26a080e5b7c0292ebd08fbb2eb540be9 (diff)
downloadsphinx-git-415ebc15c59e8b2e7fd2eb1df76017a331f8b131.tar.gz
Merge pull request #5784 from tk0miya/refactor_hack_for_py2
Refactor hack for py2
-rw-r--r--CHANGES3
-rw-r--r--doc/extdev/index.rst5
-rw-r--r--sphinx/__init__.py1
-rw-r--r--sphinx/builders/html.py3
-rw-r--r--sphinx/deprecation.py1
-rw-r--r--sphinx/domains/cpp.py5
-rw-r--r--sphinx/ext/autodoc/__init__.py3
-rw-r--r--sphinx/util/__init__.py3
-rw-r--r--sphinx/util/inspect.py12
-rw-r--r--sphinx/util/requests.py14
-rw-r--r--sphinx/writers/latex.py3
-rw-r--r--sphinx/writers/texinfo.py3
-rw-r--r--sphinx/writers/text.py5
-rw-r--r--tests/test_autodoc.py14
14 files changed, 29 insertions, 46 deletions
diff --git a/CHANGES b/CHANGES
index e4f45c12f..6434cc3a7 100644
--- a/CHANGES
+++ b/CHANGES
@@ -62,7 +62,8 @@ Deprecated
* ``sphinx.testing.util.remove_unicode_literal()``
* ``sphinx.util.attrdict``
* ``sphinx.util.force_decode()``
-* ``sphinx.util.get_matching_docs()`` is deprecated
+* ``sphinx.util.get_matching_docs()``
+* ``sphinx.util.inspect.Parameter``
* ``sphinx.util.osutil.walk()``
* ``sphinx.util.PeekableIterator``
* ``sphinx.util.pycompat.u``
diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst
index 4dc9f9480..003666217 100644
--- a/doc/extdev/index.rst
+++ b/doc/extdev/index.rst
@@ -202,6 +202,11 @@ The following is a list of deprecated interfaces.
- 4.0
- ``sphinx.util.get_matching_files()``
+ * - ``sphinx.util.inspect.Parameter``
+ - 2.0
+ - 3.0
+ - N/A
+
* - ``sphinx.util.osutil.walk()``
- 2.0
- 4.0
diff --git a/sphinx/__init__.py b/sphinx/__init__.py
index eb05bcd83..ac5a91a97 100644
--- a/sphinx/__init__.py
+++ b/sphinx/__init__.py
@@ -22,7 +22,6 @@ from .deprecation import RemovedInNextVersionWarning
if False:
# For type annotation
- # note: Don't use typing.TYPE_CHECK here (for py27 and py34).
from typing import Any # NOQA
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py
index f9a28933d..53c6c82bc 100644
--- a/sphinx/builders/html.py
+++ b/sphinx/builders/html.py
@@ -418,8 +418,7 @@ class StandaloneHTMLBuilder(Builder):
buildinfo = BuildInfo.load(fp)
if self.build_info != buildinfo:
- for docname in self.env.found_docs:
- yield docname
+ yield from self.env.found_docs
return
except ValueError as exc:
logger.warning(__('Failed to read build info file: %r'), exc)
diff --git a/sphinx/deprecation.py b/sphinx/deprecation.py
index ebf053e7b..407ac2297 100644
--- a/sphinx/deprecation.py
+++ b/sphinx/deprecation.py
@@ -13,7 +13,6 @@ import warnings
if False:
# For type annotation
- # note: Don't use typing.TYPE_CHECK here (for py27 and py34).
from typing import Any, Dict, Type # NOQA
from sphinx.util.typing import unicode # NOQA
diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py
index 262d3f6d7..2ee529625 100644
--- a/sphinx/domains/cpp.py
+++ b/sphinx/domains/cpp.py
@@ -3845,9 +3845,8 @@ class Symbol:
yield c
if not c.identOrOp.is_anon():
continue
- # TODO: change to 'yield from' when Python 2 support is dropped
- for nested in c.children_recurse_anon:
- yield nested
+
+ yield from c.children_recurse_anon
def get_lookup_key(self):
# type: () -> List[Tuple[ASTNestedNameElement, Any]]
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index 578c1d968..c6616e59b 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -458,8 +458,7 @@ class Documenter:
self.env.app.emit('autodoc-process-docstring',
self.objtype, self.fullname, self.object,
self.options, docstringlines)
- for line in docstringlines:
- yield line
+ yield from docstringlines
def get_sourcename(self):
# type: () -> unicode
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index b228ca182..b6a5b950c 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -667,8 +667,7 @@ def status_iterator(iterable, summary, color="darkgreen", length=0, verbosity=0,
stringify_func=display_chunk):
# type: (Iterable, unicode, str, int, int, Callable[[Any], unicode]) -> Iterable # NOQA
if length == 0:
- for item in old_status_iterator(iterable, summary, color, stringify_func):
- yield item
+ yield from old_status_iterator(iterable, summary, color, stringify_func)
return
l = 0
summary = bold(summary)
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index 603fa88ae..d5d2c330b 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -16,9 +16,11 @@ import inspect
import re
import sys
import typing
+import warnings
from functools import partial
from io import StringIO
+from sphinx.deprecation import RemovedInSphinx30Warning
from sphinx.util import logging
from sphinx.util.pycompat import NoneType
@@ -128,11 +130,8 @@ def isclassmethod(obj):
"""Check if the object is classmethod."""
if isinstance(obj, classmethod):
return True
- elif inspect.ismethod(obj):
- if getattr(obj, 'im_self', None): # py2
- return True
- elif getattr(obj, '__self__', None): # py3
- return True
+ elif inspect.ismethod(obj) and obj.__self__ is not None:
+ return True
return False
@@ -288,6 +287,9 @@ class Parameter:
self.default = default
self.annotation = self.empty
+ warnings.warn('sphinx.util.inspect.Parameter is deprecated.',
+ RemovedInSphinx30Warning, stacklevel=2)
+
class Signature:
"""The Signature object represents the call signature of a callable object and
diff --git a/sphinx/util/requests.py b/sphinx/util/requests.py
index c19e05cec..88c19a021 100644
--- a/sphinx/util/requests.py
+++ b/sphinx/util/requests.py
@@ -47,7 +47,7 @@ except ImportError:
# try to load requests[security] (but only if SSL is available)
try:
- import ssl
+ import ssl # NOQA
except ImportError:
pass
else:
@@ -55,17 +55,7 @@ else:
pkg_resources.require(['requests[security]'])
except (pkg_resources.DistributionNotFound,
pkg_resources.VersionConflict):
- if not getattr(ssl, 'HAS_SNI', False):
- # don't complain on each url processed about the SSL issue
- if InsecurePlatformWarning:
- requests.packages.urllib3.disable_warnings(InsecurePlatformWarning)
- warnings.warn(
- 'Some links may return broken results due to being unable to '
- 'check the Server Name Indication (SNI) in the returned SSL cert '
- 'against the hostname in the url requested. Recommended to '
- 'install "requests[security]" as a dependency or upgrade to '
- 'a python version with SNI support (Python 3 and Python 2.7.9+).'
- )
+ pass # ignored
except pkg_resources.UnknownExtra:
warnings.warn(
'Some links may return broken results due to being unable to '
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index ae3a02f09..7eb0317d9 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -926,8 +926,7 @@ class LaTeXTranslator(SphinxTranslator):
if isinstance(c, addnodes.start_of_file):
continue
elif isinstance(c, nodes.Element):
- for k in footnotes_under(c):
- yield k
+ yield from footnotes_under(c)
fnotes = {} # type: Dict[unicode, List[Union[collected_footnote, bool]]]
for fn in footnotes_under(node):
diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py
index 3c5d8bbcc..372b0f549 100644
--- a/sphinx/writers/texinfo.py
+++ b/sphinx/writers/texinfo.py
@@ -535,8 +535,7 @@ class TexinfoTranslator(SphinxTranslator):
if isinstance(c, addnodes.start_of_file):
continue
elif isinstance(c, nodes.Element):
- for k in footnotes_under(c):
- yield k
+ yield from footnotes_under(c)
fnotes = {} # type: Dict[unicode, List[Union[collected_footnote, bool]]]
for fn in footnotes_under(node):
label = cast(nodes.label, fn[0])
diff --git a/sphinx/writers/text.py b/sphinx/writers/text.py
index bf424e015..e6ef3438b 100644
--- a/sphinx/writers/text.py
+++ b/sphinx/writers/text.py
@@ -273,7 +273,6 @@ class TextWrapper(textwrap.TextWrapper):
The original _wrap_chunks uses len() to calculate width.
This method respects wide/fullwidth characters for width adjustment.
"""
- drop_whitespace = getattr(self, 'drop_whitespace', True) # py25 compat
lines = [] # type: List[unicode]
if self.width <= 0:
raise ValueError("invalid width %r (must be > 0)" % self.width)
@@ -291,7 +290,7 @@ class TextWrapper(textwrap.TextWrapper):
width = self.width - column_width(indent)
- if drop_whitespace and chunks[-1].strip() == '' and lines:
+ if self.drop_whitespace and chunks[-1].strip() == '' and lines:
del chunks[-1]
while chunks:
@@ -307,7 +306,7 @@ class TextWrapper(textwrap.TextWrapper):
if chunks and column_width(chunks[-1]) > width:
self._handle_long_word(chunks, cur_line, cur_len, width)
- if drop_whitespace and cur_line and cur_line[-1].strip() == '':
+ if self.drop_whitespace and cur_line and cur_line[-1].strip() == '':
del cur_line[-1]
if cur_line:
diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py
index feaab19f4..4fd353dc1 100644
--- a/tests/test_autodoc.py
+++ b/tests/test_autodoc.py
@@ -1028,16 +1028,13 @@ def test_autodoc_member_order(app):
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_module_scope(app):
- def convert(s):
- return re.sub('<.*>', '<FILTERED>', s) # for py2/py3
-
app.env.temp_data['autodoc:module'] = 'target'
actual = do_autodoc(app, 'attribute', 'Class.mdocattr')
- assert list(map(convert, actual)) == [
+ assert list(actual) == [
u'',
u'.. py:attribute:: Class.mdocattr',
u' :module: target',
- u' :annotation: = <FILTERED>',
+ u' :annotation: = <_io.StringIO object>',
u'',
u' should be documented as well - süß',
u' '
@@ -1046,17 +1043,14 @@ def test_autodoc_module_scope(app):
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_class_scope(app):
- def convert(s):
- return re.sub('<.*>', '<FILTERED>', s) # for py2/py3
-
app.env.temp_data['autodoc:module'] = 'target'
app.env.temp_data['autodoc:class'] = 'Class'
actual = do_autodoc(app, 'attribute', 'mdocattr')
- assert list(map(convert, actual)) == [
+ assert list(actual) == [
u'',
u'.. py:attribute:: Class.mdocattr',
u' :module: target',
- u' :annotation: = <FILTERED>',
+ u' :annotation: = <_io.StringIO object>',
u'',
u' should be documented as well - süß',
u' '