PyCQA / PyCQA/pycodestyle

E701, E302: allowing one-liners for classes

Open
#231 8 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

PEP8 allows you to type a bunch of dummy one-liners like this:

class CustomException(Exception): pass
class AnotherException(Exception): pass
class YetAnotherException(Exception): pass

But this code raises E701 (compound statement) and E302 (two lines between classes) errors. I propose to leave compound statements intact if they are a bunch of class/def definitions. This is what I've done in this pull request of autopep8 project: https://github.com/hhatto/autopep8/pull/87, but it wasn't merged since pep8 seems to be a better place for that.

This is not easy to implement since the current framework doesn't allow you to look at the next logical line. This is necessary because you need to look at previous and next line to determine if a definition is alone or inside a bunch of definitions.

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 reviewing the existing E701 and E302 handling in pycodestyle's single Python file, then compare the linked autopep8 pull request for the proposed behavior. Done means consecutive one-line class or function definitions can remain intact without those errors, while unrelated compound statements and spacing violations are still checked.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
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.