Skip to main content

A flake8 plugin to help you write better list/set/dict comprehensions.

Project description

Flake8 Comprehensions

https://img.shields.io/pypi/v/flake8-comprehensions.svg https://img.shields.io/travis/adamchainz/flake8-comprehensions.svg

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

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:

$ 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:

$ 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:

$ 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.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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8-comprehensions-1.1.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

flake8_comprehensions-1.1.1-py2.py3-none-any.whl (5.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file flake8-comprehensions-1.1.1.tar.gz.

File metadata

File hashes

Hashes for flake8-comprehensions-1.1.1.tar.gz
Algorithm Hash digest
SHA256 051f4a3e70dfb74630e0b36007f68ad03e0ee4b184ef65252d2e0c8a71d3add6
MD5 0cecea5527b11e35b5f2c8a65cd096fd
BLAKE2b-256 480bcf7791832ff094a17bb0fd4a121453f3b142733ee199662c5e6355cc1584

See more details on using hashes here.

File details

Details for the file flake8_comprehensions-1.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_comprehensions-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0dbd7ca0b8d873d0cd650ef8a5943e14a13b5f3f9eab1ca6e71aa0ab90f33ff0
MD5 1babaa8ac25f8cf08076f660c7b5c1f2
BLAKE2b-256 815b8af9a97cbdf92b29fde2be6871100d245993a559e2a241996ede839fcacd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page