Repository: asottile/yesqa

Issue:
Skip # noqa check on typing
I have a usecase that pep8 `max-line-length` is set to `79` and at the same time I have a type annotation that exceeds `79` characters. 

For example:
```
        # type: () -> Optional[List[Tuple[str, str, None, None, None, None, None]]]
```

I tried to search for multiline annotation but got nothing. I wonder whether we can remove end line noqa check on python typing comment?

Discussion:

Patch:
diff --git a/yesqa.py b/yesqa.py
index 5beb9c7..919b7f5 100644
--- a/yesqa.py
+++ b/yesqa.py
@@ -39,13 +39,11 @@ def _remove_comment(tokens, i):
 def _remove_comments(tokens):
     tokens = list(tokens)
     for i, token in tokenize_rt.reversed_enumerate(tokens):
-        if (
-                token.name == 'COMMENT' and (
-                    NOQA_RE.search(token.src) or
-                    NOQA_FILE_RE.search(token.src)
-                )
-        ):
-            _remove_comment(tokens, i)
+        if token.name == 'COMMENT':
+            if NOQA_RE.search(token.src):
+                _rewrite_noqa_comment(tokens, i, collections.defaultdict(set))
+            elif NOQA_FILE_RE.search(token.src):
+                _remove_comment(tokens, i)
     return tokens
 
 


Test patch:
diff --git a/tests/yesqa_test.py b/tests/yesqa_test.py
index 25fd493..5563293 100644
--- a/tests/yesqa_test.py
+++ b/tests/yesqa_test.py
@@ -43,6 +43,11 @@ def test_non_utf8_bytes(tmpdir, capsys):
         '"""\n' + 'a' * 40 + ' ' + 'b' * 60 + '\n""" # noqa\n',
         # don't rewrite syntax errors
         'import x  # noqa\nx() = 5\n',
+
+        'A' * 65 + ' = int\n\n\n'
+        'def f():\n'
+        '    # type: () -> ' + 'A' * 65 + '  # noqa\n'
+        '    pass\n',
     ),
 )
 def test_ok(assert_rewrite, src):
@@ -76,6 +81,10 @@ def test_ok(assert_rewrite, src):
             '# hello world\n'
             'os\n',
         ),
+        (
+            '# a  # noqa: E501\n',
+            '# a\n',
+        ),
         # file comments
         ('# flake8: noqa\nx = 1\n', 'x = 1\n'),
         ('x = 1  # flake8: noqa\n', 'x = 1\n'),