Repository: asottile/pyupgrade

Issue:
function call rewrite broken when function is parenthesized
A bit of an edge case, I haven't seen this break in the wild but it's certainly possible

```python
(
    six
).text_type(x)
```

This should produce

```python
str(x)
```

But currently produces this broken syntax:

```python
(
    str(b)
```

Discussion:

Patch:
diff --git a/pyupgrade.py b/pyupgrade.py
index 6e6051f..7313835 100644
--- a/pyupgrade.py
+++ b/pyupgrade.py
@@ -1541,6 +1541,9 @@ def _fix_py3_plus(contents_text):
         else:
             j = i
             while tokens[j].src != node.attr:
+                # timid: if we see a parenthesis here, skip it
+                if tokens[j].src == ')':
+                    return
                 j += 1
             tokens[i:j + 1] = [new_token]
 


Test patch:
diff --git a/tests/pyupgrade_test.py b/tests/pyupgrade_test.py
index d4b5bdc..ef78b95 100644
--- a/tests/pyupgrade_test.py
+++ b/tests/pyupgrade_test.py
@@ -1102,6 +1102,10 @@ def test_fix_classes(s, expected):
         'class C(six.with_metaclass(*a)): pass',
         '@six.add_metaclass(*a)\n'
         'class C: pass\n',
+        # parenthesized part of attribute
+        '(\n'
+        '    six\n'
+        ').text_type(u)\n',
     ),
 )
 def test_fix_six_noop(s):