Kaydet (Commit) 7a29a5db authored tarafından Anthony Sottile's avatar Anthony Sottile Kaydeden (comit) GitHub

Merge pull request #4 from asottile/parenthesized_function

Properly detect parens when the function is parenthesized
...@@ -179,13 +179,16 @@ def _fix_call(call, i, tokens): ...@@ -179,13 +179,16 @@ def _fix_call(call, i, tokens):
# #
# func_name(arg, arg, arg) # func_name(arg, arg, arg)
# ^ outer paren # ^ outer paren
brace_start, brace_end = '(', ')'
first_paren = None first_paren = None
paren_stack = [] paren_stack = []
for i in range(i, len(tokens)): for i in range(i, len(tokens)):
token = tokens[i] token = tokens[i]
if token.src == '(': if token.src == brace_start:
paren_stack.append(i) paren_stack.append(i)
elif token.src == ')': # the ast lies to us about the beginning of parenthesized functions.
# See #3. (why we make sure there's something to pop here)
elif token.src == brace_end and paren_stack:
paren_stack.pop() paren_stack.pop()
if (token.line, token.utf8_byte_offset) in call.arg_offsets: if (token.line, token.utf8_byte_offset) in call.arg_offsets:
...@@ -194,7 +197,7 @@ def _fix_call(call, i, tokens): ...@@ -194,7 +197,7 @@ def _fix_call(call, i, tokens):
else: else:
raise AssertionError('Past end?') raise AssertionError('Past end?')
_fix_inner('(', ')', first_paren, tokens) _fix_inner(brace_start, brace_end, first_paren, tokens)
def _fix_literal(literal, i, tokens): def _fix_literal(literal, i, tokens):
......
...@@ -42,6 +42,10 @@ xfailif_lt_py35 = pytest.mark.xfail(sys.version_info < (3, 5), reason='py35+') ...@@ -42,6 +42,10 @@ xfailif_lt_py35 = pytest.mark.xfail(sys.version_info < (3, 5), reason='py35+')
'x((\n' 'x((\n'
' 1,\n' ' 1,\n'
'))', '))',
# regression test for #3
'(\n'
' a\n'
').f(b)',
), ),
) )
def test_fix_calls_noops(src): def test_fix_calls_noops(src):
......
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