Metadata-Version: 2.0
Name: flake8-comprehensions
Version: 1.1.0
Summary: A flake8 plugin to help you write better list/set/dict comprehensions.
Home-page: https://github.com/adamchainz/flake8-comprehensions
Author: Adam Johnson
Author-email: me@adamj.eu
License: ISCL
Keywords: flake8,comprehensions,list comprehension,set comprehension,dict comprehension
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: ISC License (ISCL)
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.5
Requires-Dist: flake8

=====================
Flake8 Comprehensions
=====================

.. image:: https://img.shields.io/pypi/v/flake8-comprehensions.svg
        :target: https://pypi.python.org/pypi/flake8-comprehensions

.. image:: https://img.shields.io/travis/adamchainz/flake8-comprehensions.svg
        :target: https://travis-ci.org/adamchainz/flake8-comprehensions

A `flake8 <https://flake8.readthedocs.org/en/latest/index.html>`_ plugin that
helps you write better list/set/dict comprehensions.

* Free software: ISC license

Installation
------------

Install from ``pip`` with:

.. code-block:: sh

     pip install flake8-comprehensions

It will then automatically be run as part of ``flake8``; you can check it has
been picked up with:

.. code-block:: sh

    $ flake8 --version
    2.4.1 (pep8: 1.7.0, pyflakes: 0.8.1, flake8-comprehensions: 1.0.0, mccabe: 0.3.1) CPython 2.7.11 on Darwin


Rules
-----

C400: Unnecessary generator
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Complains about unnecessary use of a generator inside a call to
``list()``/``set()``/``dict()`` when an equivalent comprehension would do.
For example:

* ``list(f(x) for x in foo)`` -> ``[f(x) for x in foo]``
* ``set(f(x) for x in foo)`` -> ``{f(x) for x in foo}``
* ``dict((x, f(x)) for x in foo)`` -> ``{x: f(x) for x in foo}``

This rule triggers a message like:

.. code-block:: sh

    $ flake8 file.py
    file.py:1:1: C400 Unnecessary generator - rewrite as a list comprehension.


C401: Unnecessary list comprehension
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Complains about unnecessary use of a list comprehension, for example when
inside a ``set()`` call. For example:

* ``set([f(x) for x in foo])`` -> ``{f(x) for x in foo}``
* ``dict([(x, f(x)) for x in foo])`` -> ``{x: f(x) for x in foo}``

This triggers a message like:

.. code-block:: sh

    $ flake8 file.py
    file.py:1:1: C401 Unnecessary list comprehension - rewrite as a set comprehension.


C402: Unnecessary list literal
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Complains about unnecessary list literals, for example when inside a ``set()``
call. For example:

* ``set([1, 2])`` -> ``{1, 2}``
* ``set([])`` -> ``set()``
* ``dict([])`` -> ``{}``
* ``dict([(1, 2)])`` -> ``{1: 2}``

This triggers a message like:

.. code-block:: sh

    $ flake8 file.py
    file.py:1:1: C402 Unnecessary list literal - rewrite as a set literal.


=======
History
=======

Pending Release
---------------

* New release notes here

1.1.0 (2016-04-06)
------------------

* ``C401`` rule that complains about unnecessary list comprehensions inside
  calls to ``set()`` or ``dict()``.
* ``C402`` rule that complains about unnecessary list literals inside calls to
  ``set()`` or ``dict()``.


1.0.0 (2016-04-05)
------------------

* ``C400`` rule that complains about an unnecessary usage of a generator when a
  list/set/dict comprehension would do.


