A flake8 plugin to help you write better list/set/dict comprehensions.
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
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.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flake8-comprehensions-1.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9838cacae5918273aeef5be7533f8b1ba8f4386d0be2c47a07132dd5a2680542 |
|
MD5 | b49800f150e0aefd80331fb4de57aeaa |
|
BLAKE2b-256 | d4e1984e4b6cfdab5d00114c330a0446b9f159597e621fa81a5e6646789f372b |
Hashes for flake8_comprehensions-1.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d82b185ced11dc9277dc91e3bb083ce2e158844a22e4c4a0a18f638cd90a3f10 |
|
MD5 | 7231c8fa83a1724889e405ff54c18de9 |
|
BLAKE2b-256 | 477c475869de8a2aa0913db30e79168fbceec0d6c27539d9e57e84c472be45ea |