--- id: flake8-comprehensions version: "3.17.0" license: MIT license_treatment: permissive maintenance: active --- # flake8-comprehensions — A flake8 plugin to help you write better list/set/dict comprehensions. License: permissive · Maintenance: active · Downloads: 1.9M/mo ## What it is and what it does flake8-comprehensions is a flake8 plugin that analyzes Python code to identify and flag inefficient or redundant patterns involving comprehensions, generators, and built-in type constructors. It enforces a suite of rules (C400–C417) that catch common mistakes: unnecessary generator expressions wrapped in list/set/dict calls, list comprehensions passed to set/dict constructors, redundant literal syntax, and inefficient double-casting of iterables. The plugin integrates directly into flake8's linting pipeline. When installed, it runs automatically as part of flake8's checks (unless explicitly disabled via configuration). It emits specific error codes and suggestions for how to rewrite each pattern more idiomatically—for example, replacing `list(x for x in foo)` with `[x for x in foo]` or `set([1, 2])` with `{1, 2}`. The plugin is particularly useful in codebases that prioritize readability and performance, helping developers adopt Pythonic idioms consistently. Use it for: - Enforce consistent comprehension style across a team codebase during CI/CD linting. - Catch performance anti-patterns like unnecessary generator wrapping or double-casting in code review. - Teach Python developers idiomatic comprehension syntax and when to use set/dict literals. - Identify redundant list comprehensions that can be simplified to direct set() or dict() calls. - Flag inefficient sorted() or reversed() patterns that can be optimized with built-in arguments. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. A flake8 plugin that detects and suggests rewrites for inefficient or redundant list, set, and dict comprehensions and related constructs. Yes. The plugin is actively maintained, has no known vulnerabilities, and low install friction. It fills a specific and well-defined niche—catching comprehension anti-patterns—that most general linters do not cover. Install it if your team values code idiomaticity and performance-conscious Python style. ## Install pip install flake8-comprehensions uv add flake8-comprehensions poetry add flake8-comprehensions ## Installing flake8-comprehensions Before you install: Low friction: a pure-Python wheel with only flake8 as a runtime dependency. Actively maintained with a recent release and no known vulnerabilities. License in practice: MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects. Quickstart: pip install flake8-comprehensions Then add C4 to flake8's select setting if defined, or it activates by default. Run flake8 on your code to see violations like C400-C417. Requires Python 3.9 or later. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 1.9M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags flake8 comprehension linting, list set dict comprehension checker, python comprehension optimization, flake8 code quality plugin, detect unnecessary generators, comprehension best practices, flake8 performance linting, flake8-plugin, code-style, linting [View on SkillFed](https://skillfed.io/packages/flake8-comprehensions) · [View on PyPI](https://pypi.org/project/flake8-comprehensions/)