PyCQA / PyCQA/flake8-bugbear

How about checking that you're not using a list for an in?

Open
#139 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
1.1k
Forks
123
Avg merge
2d 5h
Merged PRs (30d)
5

Description

A very common pattern:

candidates = [some for some in another_stuff()]
if me in candidates:
    do_stuff()

If candidates is only used for an in, then we have 2 alternatives that are going to be more performant than the above in 100% of the cases:

Using a generator:

-candidates = [some for some in another_stuff()]
+candidates = (some for some in another_stuff())

Or using a set:

-candidates = [some for some in another_stuff()]
+candidates = {some for some in another_stuff()}

How about linting this?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository files, tests, or entry points are named. Start by reviewing the existing Python lint-rule structure and determine how to identify list comprehensions used only for membership checks; the work is done when this pattern produces a documented warning without flagging cases where list semantics are needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.