This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

flake8-comprehensions

A flake8 plugin that helps you write better list/set/dict comprehensions.

  • Free software: ISC license

Installation

Install from pip with:

pip install flake8-comprehensions

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

$ 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

Code Rule
C400 Unnecessary generator - rewrite as a list comprehension.
C401 Unnecessary generator - rewrite as a set comprehension.
C402 Unnecessary generator - rewrite as a dict comprehension.
C403 Unnecessary list comprehension - rewrite as a set comprehension.
C404 Unnecessary list comprehension - rewrite as a dict comprehension.
C405 Unnecessary list literal - rewrite as a set literal.
C406 Unnecessary list literal - rewrite as a dict literal.
C407 Unnecessary list comprehension - ‘<builtin>’ can take a generator.

Examples

C400-402: Unnecessary generator

It’s unnecessary to use list, set, or dict around a generator expression, since there are equivalent comprehensions for these types. For example:

  • list(f(x) for x in foo) is better as [f(x) for x in foo]
  • set(f(x) for x in foo) is better as {f(x) for x in foo}
  • dict((x, f(x)) for x in foo) is better as {x: f(x) for x in foo}

C403-404: Unnecessary list comprehension

It’s unnecessary to use a list comprehension inside a call to set or dict, since there are equivalent comprehensions for these types. For example:

  • set([f(x) for x in foo]) is better as {f(x) for x in foo}
  • dict([(x, f(x)) for x in foo]) is better as {x: f(x) for x in foo}

C405-406: Unnecessary list literal

It’s unnecessary to use a list literal within a call to set or dict since there is literal syntax for these types. For example:

  • set([1, 2]) is better as {1, 2}
  • set([]) is better as set()
  • dict([]) is better as {}
  • dict([(1, 2)]) is better as {1: 2}

C407: Unnecessary list comprehension - ‘<builtin>’ can take a generator

It’s unnecessary to pass a list comprehension to some builtins that can take generators instead. For example:

  • sum([x ** 2 for x in range(10)]) is better as sum(x ** 2 for x in range(10))
  • all([foo.bar for foo in foos]) is better as all(foo.bar for foo in foos)

The list of builtins that are checked for are:

  • all
  • any
  • frozenset
  • max
  • min
  • sorted
  • sum
  • tuple

History

Pending Release

  • New release notes here

1.2.1 (2016-06-27)

  • C407 rule that complains about unnecessary list comprehensions inside builtins that can work on generators.

1.2.0 (2016-07-11)

  • Split all rule codes by type. This allows granular selection of the rules in flake8 configuration.

1.1.1 (2016-04-06)

  • Fix crash on method calls

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.
Release History

Release History

1.2.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.2.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
flake8_comprehensions-1.2.1-py2.py3-none-any.whl (5.8 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Jul 27, 2016
flake8-comprehensions-1.2.1.tar.gz (5.9 kB) Copy SHA256 Checksum SHA256 Source Jul 27, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting