Skip to content

Commit

Permalink
Merge pull request sphinx-doc#8378 from tk0miya/drop_py35_support
Browse files Browse the repository at this point in the history
Drop code for supporting py35
  • Loading branch information
tk0miya committed Nov 8, 2020
2 parents 8bf8416 + 0914c92 commit a3145be
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 65 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -51,7 +51,7 @@
'pytest',
'pytest-cov',
'html5lib',
'typed_ast', # for py35-37
'typed_ast', # for py36-37
'cython',
],
}
Expand Down
12 changes: 5 additions & 7 deletions sphinx/domains/python.py
Expand Up @@ -102,6 +102,11 @@ def _parse_annotation(annotation: str, env: BuildEnvironment = None) -> List[Nod
def unparse(node: ast.AST) -> List[Node]:
if isinstance(node, ast.Attribute):
return [nodes.Text("%s.%s" % (unparse(node.value)[0], node.attr))]
elif isinstance(node, ast.Constant): # type: ignore
if node.value is Ellipsis:
return [addnodes.desc_sig_punctuation('', "...")]
else:
return [nodes.Text(node.value)]
elif isinstance(node, ast.Expr):
return unparse(node.value)
elif isinstance(node, ast.Index):
Expand Down Expand Up @@ -137,13 +142,6 @@ def unparse(node: ast.AST) -> List[Node]:

return result
else:
if sys.version_info >= (3, 6):
if isinstance(node, ast.Constant): # type: ignore
if node.value is Ellipsis:
return [addnodes.desc_sig_punctuation('', "...")]
else:
return [nodes.Text(node.value)]

if sys.version_info < (3, 8):
if isinstance(node, ast.Ellipsis):
return [addnodes.desc_sig_punctuation('', "...")]
Expand Down
10 changes: 2 additions & 8 deletions sphinx/pycode/parser.py
Expand Up @@ -10,7 +10,6 @@
import inspect
import itertools
import re
import sys
import tokenize
from collections import OrderedDict
from inspect import Signature
Expand All @@ -27,12 +26,6 @@
emptyline_re = re.compile('^\\s*(#.*)?$')


if sys.version_info >= (3, 6):
ASSIGN_NODES = (ast.Assign, ast.AnnAssign)
else:
ASSIGN_NODES = (ast.Assign)


def filter_whitespace(code: str) -> str:
return code.replace('\f', ' ') # replace FF (form feed) with whitespace

Expand Down Expand Up @@ -408,7 +401,8 @@ def visit_AnnAssign(self, node: ast.AnnAssign) -> None:

def visit_Expr(self, node: ast.Expr) -> None:
"""Handles Expr node and pick up a comment if string."""
if (isinstance(self.previous, ASSIGN_NODES) and isinstance(node.value, ast.Str)):
if (isinstance(self.previous, (ast.Assign, ast.AnnAssign)) and
isinstance(node.value, ast.Str)):
try:
targets = get_assign_targets(self.previous)
varnames = get_lvar_names(targets[0], self.get_self())
Expand Down
2 changes: 1 addition & 1 deletion sphinx/util/inspect.py
Expand Up @@ -271,7 +271,7 @@ def is_singledispatch_method(obj: Any) -> bool:
try:
from functools import singledispatchmethod # type: ignore
return isinstance(obj, singledispatchmethod)
except ImportError: # py35-37
except ImportError: # py36-37
return False


Expand Down
2 changes: 1 addition & 1 deletion sphinx/util/typing.py
Expand Up @@ -22,7 +22,7 @@
from typing import _ForwardRef # type: ignore

class ForwardRef:
"""A pseudo ForwardRef class for py35 and py36."""
"""A pseudo ForwardRef class for py36."""
def __init__(self, arg: Any, is_argument: bool = True) -> None:
self.arg = arg

Expand Down
37 changes: 13 additions & 24 deletions tests/test_ext_autodoc.py
Expand Up @@ -290,7 +290,6 @@ def foo3(self, d='\n'):
'(b, c=42, *d, **e)'


@pytest.mark.skipif(sys.version_info < (3, 5), reason='typing is available since python3.5.')
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_process_signature_typing_generic(app):
actual = do_autodoc(app, 'class', 'target.generic_class.A', {})
Expand Down Expand Up @@ -1559,7 +1558,6 @@ def test_partialmethod_undoc_members(app):
assert list(actual) == expected


@pytest.mark.skipif(sys.version_info < (3, 6), reason='py36+ is available since python3.6.')
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_typed_instance_variables(app):
options = {"members": None,
Expand Down Expand Up @@ -1653,7 +1651,6 @@ def test_autodoc_typed_instance_variables(app):
]


@pytest.mark.skipif(sys.version_info < (3, 6), reason='py36+ is available since python3.6.')
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_typed_inherited_instance_variables(app):
options = {"members": None,
Expand Down Expand Up @@ -1783,7 +1780,6 @@ def test_autodoc_Annotated(app):
]


@pytest.mark.skipif(sys.version_info < (3, 6), reason='py36+ is required.')
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_TYPE_CHECKING(app):
options = {"members": None,
Expand Down Expand Up @@ -1832,26 +1828,19 @@ def test_autodoc_for_egged_code(app):
def test_singledispatch(app):
options = {"members": None}
actual = do_autodoc(app, 'module', 'target.singledispatch', options)
if sys.version_info < (3, 6):
# check the result via "in" because the order of singledispatch signatures is
# usually changed (because dict is not OrderedDict yet!)
assert '.. py:function:: func(arg, kwarg=None)' in actual
assert ' func(arg: int, kwarg=None)' in actual
assert ' func(arg: str, kwarg=None)' in actual
else:
assert list(actual) == [
'',
'.. py:module:: target.singledispatch',
'',
'',
'.. py:function:: func(arg, kwarg=None)',
' func(arg: int, kwarg=None)',
' func(arg: str, kwarg=None)',
' :module: target.singledispatch',
'',
' A function for general use.',
'',
]
assert list(actual) == [
'',
'.. py:module:: target.singledispatch',
'',
'',
'.. py:function:: func(arg, kwarg=None)',
' func(arg: int, kwarg=None)',
' func(arg: str, kwarg=None)',
' :module: target.singledispatch',
'',
' A function for general use.',
'',
]


@pytest.mark.skipif(sys.version_info < (3, 8),
Expand Down
27 changes: 10 additions & 17 deletions tests/test_ext_autodoc_autofunction.py
Expand Up @@ -118,23 +118,16 @@ def test_decorated(app):
def test_singledispatch(app):
options = {}
actual = do_autodoc(app, 'function', 'target.singledispatch.func', options)
if sys.version_info < (3, 6):
# check the result via "in" because the order of singledispatch signatures is
# usually changed (because dict is not OrderedDict yet!)
assert '.. py:function:: func(arg, kwarg=None)' in actual
assert ' func(arg: int, kwarg=None)' in actual
assert ' func(arg: str, kwarg=None)' in actual
else:
assert list(actual) == [
'',
'.. py:function:: func(arg, kwarg=None)',
' func(arg: int, kwarg=None)',
' func(arg: str, kwarg=None)',
' :module: target.singledispatch',
'',
' A function for general use.',
'',
]
assert list(actual) == [
'',
'.. py:function:: func(arg, kwarg=None)',
' func(arg: int, kwarg=None)',
' func(arg: str, kwarg=None)',
' :module: target.singledispatch',
'',
' A function for general use.',
'',
]


@pytest.mark.sphinx('html', testroot='ext-autodoc')
Expand Down
3 changes: 1 addition & 2 deletions tests/test_pycode_parser.py
Expand Up @@ -95,8 +95,7 @@ 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():
def test_annotated_assignment():
source = ('a: str = "Sphinx" #: comment\n'
'b: int = 1\n'
'"""string on next line"""\n'
Expand Down
5 changes: 1 addition & 4 deletions tests/test_util_inspect.py
Expand Up @@ -220,10 +220,7 @@ def test_signature_annotations():

# type hints by string
sig = inspect.signature(Node.children)
if (3, 5, 0) <= sys.version_info < (3, 5, 3):
assert stringify_signature(sig) == '(self) -> List[Node]'
else:
assert stringify_signature(sig) == '(self) -> List[typing_test_data.Node]'
assert stringify_signature(sig) == '(self) -> List[typing_test_data.Node]'

sig = inspect.signature(Node.__init__)
assert stringify_signature(sig) == '(self, parent: Optional[Node]) -> None'
Expand Down

0 comments on commit a3145be

Please sign in to comment.