PyCQA / PyCQA/flake8-bugbear

Thoughts on improving B902?

Open
#33 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I think B902 is great for detecting errors like this:

@classmethod
def foo(self):
    ...

However, I also find myself # noqa:ing it a bit too frequently. Here are some instances where I think it could be safely relaxed for everyone:

  • Allow _cls instead of cls (ditto for metacls). Rationale: this can be required when a method needs to take, or transparently pass through, a keyword argument with one of these names.
  • The first argument to __new__ of classes that subclass type should probably be called metacls, not cls. And similarly — regular instance methods on metaclasses should take cls, and any classmethods should take metacls.
  • Consider allowing subcls / submetacls (depending on inheritance) for __init_subclass__, since that is actually significantly clearer.

What do you think?

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

Start at the B902 rule entry point and review how it currently handles classmethod, new, and init_subclass. Compare the proposed _cls, metacls, subcls, and submetacls cases with the existing behavior; done requires an agreed scope and verified rule changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.