PyCQA / PyCQA/pycodestyle

Add error on imports inside class definitions

Open
#351 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extension feature undecided
Dominant language
Python
Stars
5.2k
Forks
754
PR merge metrics
No merged PRs in 30d

Description

Opening a new issue for this based on discussion from @ncoghlan on issue #304 .

Flagging module level imports that don't occur at the start of the file and imports inside class definitions as errors seem like reasonable additions to me. The latter is technically going beyond the text of the PEP itself, but I'd be incredibly surprised if anyone complained about you flagging it as an error - while imports at class scope are permitted by the language, deliberately adding a module as a class attribute would just be weird.

Contributor guide

Open the contributing guide

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 by reading issue #304 and the repository's single Python file to find the existing checks for module-level imports. Determine where imports inside class definitions are identified and review any nearby tests, if present. Done means the checker reports class-scope imports as errors without changing the handling of permitted imports.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 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.