Repository: asottile/add-trailing-comma

Issue:
AssertionError on valid syntax
```python
with a:  
    pass 
[b] = {1}
```

produces this error with add-trailing-comma version 0.5.1:

```
Traceback (most recent call last):
  File "/nail/home/ckuehl/.pre-commit/repo3dPrz7/py_env-python2.7/bin/add-trailing-comma", line 9, in <module>
    load_entry_point('add-trailing-comma==0.5.1', 'console_scripts', 'add-trailing-comma')()
  File "/nail/home/ckuehl/.pre-commit/repo3dPrz7/py_env-python2.7/local/lib/python2.7/site-packages/add_trailing_comma.py", line 378, in main
    ret |= fix_file(filename, args)
  File "/nail/home/ckuehl/.pre-commit/repo3dPrz7/py_env-python2.7/local/lib/python2.7/site-packages/add_trailing_comma.py", line 358, in fix_file
    contents_text = _fix_src(contents_text, args.py35_plus)
  File "/nail/home/ckuehl/.pre-commit/repo3dPrz7/py_env-python2.7/local/lib/python2.7/site-packages/add_trailing_comma.py", line 333, in _fix_src
    fixes.append((True, _find_simple(i, tokens)))
  File "/nail/home/ckuehl/.pre-commit/repo3dPrz7/py_env-python2.7/local/lib/python2.7/site-packages/add_trailing_comma.py", line 154, in _find_simple
    raise AssertionError('Past end?')
AssertionError: Past end
```

Discussion:

Patch:
diff --git a/add_trailing_comma.py b/add_trailing_comma.py
index 926f9de..2e71af5 100644
--- a/add_trailing_comma.py
+++ b/add_trailing_comma.py
@@ -325,6 +325,9 @@ def _fix_src(contents_text, py35_plus, py36_plus):
 
     tokens = src_to_tokens(contents_text)
     for i, token in _changing_list(tokens):
+        # DEDENT is a zero length token
+        if not token.src:
+            continue
         key = Offset(token.line, token.utf8_byte_offset)
 
         fixes = []


Test patch:
diff --git a/tests/add_trailing_comma_test.py b/tests/add_trailing_comma_test.py
index 82e51eb..a370743 100644
--- a/tests/add_trailing_comma_test.py
+++ b/tests/add_trailing_comma_test.py
@@ -149,9 +149,13 @@ def test_fixes_calls(src, expected):
         '[1, 2, 3, 4]',
         '{1, 2, 3, 4}',
         '{1: 2, 3: 4}',
+        # Regression test for #26
+        'if True:\n'
+        '    pass\n'
+        '[x] = {y}',
     ),
 )
-def test_noop_one_line_literals(src):
+def test_noop_literals(src):
     assert _fix_src(src, py35_plus=False, py36_plus=False) == src