Merge pull request #8378 from tk0miya/drop_py35_support

Drop code for supporting py35
This commit is contained in:
Takeshi KOMIYA 2020-11-08 12:36:16 +09:00 committed by GitHub
commit a3145beddf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 35 additions and 65 deletions

View File

@ -51,7 +51,7 @@ extras_require = {
'pytest',
'pytest-cov',
'html5lib',
'typed_ast', # for py35-37
'typed_ast', # for py36-37
'cython',
],
}

View File

@ -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):
@ -137,13 +142,6 @@ def _parse_annotation(annotation: str, env: BuildEnvironment = None) -> List[Nod
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('', "...")]

View File

@ -10,7 +10,6 @@
import inspect
import itertools
import re
import sys
import tokenize
from collections import OrderedDict
from inspect import Signature
@ -27,12 +26,6 @@ indent_re = re.compile('^\\s*$')
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
@ -408,7 +401,8 @@ class VariableCommentPicker(ast.NodeVisitor):
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())

View File

@ -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

View File

@ -22,7 +22,7 @@ else:
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

View File

@ -290,7 +290,6 @@ def test_format_signature(app):
'(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', {})
@ -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,
@ -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,
@ -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,
@ -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),

View File

@ -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')

View File

@ -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'

View File

@ -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'