Repository: adamchainz/flake8-comprehensions (python)

Issue:
Add new rule for enumerate(<comprehension>)
Suggest change from `enumerate(<comprehension>)` to `enumerate(<generator>)` with the caveat that the generator needs to be wrapped in parentheses if [`enumerate()`](https://docs.python.org/3/library/functions.html#enumerate) is passed the `start` argument.

Pull request description:
Added missing builtin enumerate to C407
Fixes #61. Thanks @pope1ni for the original PR in #108.

Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 4083bad..e624a53 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -7,6 +7,8 @@ Pending Release
 
 .. Insert new release notes below this line
 
+* Add missing builtin ``enumerate`` to ``C407``.
+
 2.0.0 (2019-02-02)
 ------------------
 
diff --git a/README.rst b/README.rst
index 373a72d..94145a2 100644
--- a/README.rst
+++ b/README.rst
@@ -106,6 +106,7 @@ The list of builtins that are checked for are:
 
 * ``all``
 * ``any``
+* ``enumerate``
 * ``frozenset``
 * ``max``
 * ``min``
diff --git a/flake8_comprehensions.py b/flake8_comprehensions.py
index a8aa708..5496e83 100644
--- a/flake8_comprehensions.py
+++ b/flake8_comprehensions.py
@@ -126,7 +126,7 @@ class ComprehensionChecker(object):
                 elif (
                     n_args == 1 and
                     isinstance(node.args[0], ast.ListComp) and
-                    node.func.id in ('all', 'any', 'frozenset', 'max', 'min', 'sorted', 'sum', 'tuple')
+                    node.func.id in ('all', 'any', 'enumerate', 'frozenset', 'max', 'min', 'sorted', 'sum', 'tuple')
                 ):
 
                     yield (


Test patch:
diff --git a/test_flake8_comprehensions.py b/test_flake8_comprehensions.py
index 6a5135c..087b1e2 100644
--- a/test_flake8_comprehensions.py
+++ b/test_flake8_comprehensions.py
@@ -271,6 +271,16 @@ def test_C407_max_fail_1(flake8dir):
     ]
 
 
+def test_C407_enumerate_fail_1(flake8dir):
+    flake8dir.make_example_py("""
+        foo = enumerate([x for x in range(10)])
+    """)
+    result = flake8dir.run_flake8()
+    assert result.out_lines == [
+        "./example.py:1:7: C407 Unnecessary list comprehension - 'enumerate' can take a generator.",
+    ]
+
+
 def test_C407_tuple_pass_1(flake8dir):
     flake8dir.make_example_py("""
         foo = ()