Kaydet (Commit) c2bf723a authored tarafından Anthony Sottile's avatar Anthony Sottile

Remove automatic py35+ syntax detection

üst 30d7eb8a
......@@ -86,8 +86,8 @@ This has the following benefits:
### trailing commas for function calls with unpackings
If `--py35-plus` is passed (or python3.5+ syntax is automatically detected),
`add-trailing-comma` will also perform the following change:
If `--py35-plus` is passed, `add-trailing-comma` will also perform the
following change:
```diff
x(
......
......@@ -62,24 +62,16 @@ class FindNodes(ast.NodeVisitor):
self.calls = {}
self.funcs = {}
self.literals = {}
self.has_new_syntax = False
def _visit_literal(self, node, key='elts', **kwargs):
for elt in getattr(node, key):
if _is_star_arg(elt): # pragma: no cover (PY35+)
self.has_new_syntax = True
if getattr(node, key):
key = Offset(node.lineno, node.col_offset)
self.literals[key] = Literal(node, **kwargs)
self.generic_visit(node)
self.generic_visit(node)
visit_Set = visit_List = _visit_literal
def visit_Dict(self, node):
# unpackings are represented as a `None` key
if None in node.keys: # pragma: no cover (PY35+)
self.has_new_syntax = True
self._visit_literal(node, key='values')
def visit_Tuple(self, node):
......@@ -119,12 +111,6 @@ class FindNodes(ast.NodeVisitor):
key = Offset(node.lineno, node.col_offset)
self.calls[key] = Call(node, has_starargs, arg_offsets)
if (
sum(_is_star_arg(n) for n in node.args) > 1 or
sum(_is_star_star_kwarg(n) for n in node.keywords) > 1
): # pragma: no cover (PY35+)
self.has_new_syntax = True
self.generic_visit(node)
def visit_FunctionDef(self, node):
......@@ -134,14 +120,11 @@ class FindNodes(ast.NodeVisitor):
getattr(node.args, 'kwonlyargs', None)
)
offsets = set()
for argnode in node.args.args:
offset = _to_offset(argnode)
offsets.add(offset)
arg_offsets = {_to_offset(arg) for arg in node.args.args}
if offsets and not has_starargs:
if arg_offsets and not has_starargs:
key = Offset(node.lineno, node.col_offset)
self.funcs[key] = Func(node, offsets)
self.funcs[key] = Func(node, arg_offsets)
self.generic_visit(node)
......@@ -325,7 +308,6 @@ def _fix_src(contents_text, py35_plus):
visitor = FindNodes()
visitor.visit(ast_obj)
py35_plus = py35_plus or visitor.has_new_syntax
tokens = src_to_tokens(contents_text)
for i, token in _changing_list(tokens):
......
......@@ -84,24 +84,6 @@ def test_py35_plus_rewrite():
)
@xfailif_lt_py35
@pytest.mark.parametrize(
'syntax',
(
'(1, 2, *a)\n',
'[1, 2, *a]\n',
'{1, 2, *a}\n',
'{1: 2, **k}\n',
'y(*args1, *args2)\n',
'y(**kwargs1, **kwargs2)\n',
),
)
def test_auto_detected_py35_plus_rewrite(syntax):
src = syntax + 'x(\n *args\n)'
expected = syntax + 'x(\n *args,\n)'
assert _fix_src(src, py35_plus=False) == expected
@pytest.mark.parametrize(
('src', 'expected'),
(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment