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

Some minor renaming

üst cfaec3b5
......@@ -239,7 +239,7 @@ def _fix_literal(literal, i, tokens):
_fix_inner(brace_start, brace_end, i, tokens)
def _fix_commas(contents_text, py35_plus):
def _fix_src(contents_text, py35_plus):
try:
ast_obj = ast_parse(contents_text)
except SyntaxError:
......@@ -247,6 +247,7 @@ def _fix_commas(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 reversed(tuple(enumerate(tokens))):
......@@ -254,7 +255,7 @@ def _fix_commas(contents_text, py35_plus):
if key in visitor.calls:
call = visitor.calls[key]
# Only fix stararg calls if asked to
if not call.star_args or py35_plus or visitor.has_new_syntax:
if not call.star_args or py35_plus:
_fix_call(call, i, tokens)
elif key in visitor.literals:
_fix_literal(visitor.literals[key], i, tokens)
......@@ -275,7 +276,7 @@ def fix_file(filename, args):
print('{} is non-utf-8 (not supported)'.format(filename))
return 1
contents_text = _fix_commas(contents_text, args.py35_plus)
contents_text = _fix_src(contents_text, args.py35_plus)
if contents_text != contents_text_orig:
print('Rewriting {}'.format(filename))
......
......@@ -7,7 +7,7 @@ import sys
import pytest
from add_trailing_comma import _fix_commas
from add_trailing_comma import _fix_src
from add_trailing_comma import main
......@@ -49,7 +49,7 @@ xfailif_lt_py35 = pytest.mark.xfail(sys.version_info < (3, 5), reason='py35+')
),
)
def test_fix_calls_noops(src):
ret = _fix_commas(src, py35_plus=False)
ret = _fix_src(src, py35_plus=False)
assert ret == src
......@@ -66,7 +66,7 @@ def test_ignores_invalid_ast_node():
' """\n'
')'
)
assert _fix_commas(src, py35_plus=False) == src
assert _fix_src(src, py35_plus=False) == src
def test_py35_plus_rewrite():
......@@ -75,7 +75,7 @@ def test_py35_plus_rewrite():
' *args\n'
')'
)
ret = _fix_commas(src, py35_plus=True)
ret = _fix_src(src, py35_plus=True)
assert ret == (
'x(\n'
' *args,\n'
......@@ -98,7 +98,7 @@ def test_py35_plus_rewrite():
def test_auto_detected_py35_plus_rewrite(syntax):
src = syntax + 'x(\n *args\n)'
expected = syntax + 'x(\n *args,\n)'
assert _fix_commas(src, py35_plus=False) == expected
assert _fix_src(src, py35_plus=False) == expected
@pytest.mark.parametrize(
......@@ -134,7 +134,7 @@ def test_auto_detected_py35_plus_rewrite(syntax):
),
)
def test_fixes_calls(src, expected):
assert _fix_commas(src, py35_plus=False) == expected
assert _fix_src(src, py35_plus=False) == expected
@pytest.mark.parametrize(
......@@ -147,7 +147,7 @@ def test_fixes_calls(src, expected):
),
)
def test_noop_one_line_literals(src):
assert _fix_commas(src, py35_plus=False) == src
assert _fix_src(src, py35_plus=False) == src
@pytest.mark.parametrize(
......@@ -194,7 +194,7 @@ def test_noop_one_line_literals(src):
),
)
def test_fixes_literals(src, expected):
assert _fix_commas(src, py35_plus=False) == expected
assert _fix_src(src, py35_plus=False) == expected
@xfailif_lt_py35
......@@ -240,7 +240,7 @@ def test_fixes_literals(src, expected):
),
)
def test_fixes_py35_plus_literals(src, expected):
assert _fix_commas(src, py35_plus=False) == expected
assert _fix_src(src, py35_plus=False) == expected
def test_noop_tuple_literal_without_braces():
......@@ -250,7 +250,7 @@ def test_noop_tuple_literal_without_braces():
' 2, \\\n'
' 3'
)
assert _fix_commas(src, py35_plus=False) == src
assert _fix_src(src, py35_plus=False) == src
@pytest.mark.parametrize(
......@@ -276,7 +276,7 @@ def test_noop_tuple_literal_without_braces():
),
)
def test_noop_function_defs(src):
assert _fix_commas(src, py35_plus=False) == src
assert _fix_src(src, py35_plus=False) == src
@pytest.mark.parametrize(
......@@ -294,7 +294,7 @@ def test_noop_function_defs(src):
),
)
def test_fixes_defs(src, expected):
assert _fix_commas(src, py35_plus=False) == expected
assert _fix_src(src, py35_plus=False) == expected
def test_main_trivial():
......
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