PyCQA / PyCQA/flake8-bugbear

Question: B027 empty method in an abstract base class

Open
#301 3 comments 3 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

Short question on the reason behind newly added B027: If we have an ABC

from abc import ABC, abstractmethod

class MyABC(ABC):
    
    def method(self):
        """
        Some method that does nothing by default. Derived classes can choose to override it.
        """
        pass

    @abstractmethod
    def method2(self):
        """
        Another method. Derived classes MUST define it.
        """

B027 will raise on the first method for not being declared abstract.

Is there a way of allowing it to be empty despite the class being abstract? (Besides noqa and besides overriding them with an empty method in derived classes.) I would argue that there is reason to have empty methods provided by the ABC (interface) where the default implementation is to do nothing, but that derived classes can choose to override (e.g. if they need to perform some initialization / tear down of servers in my case), as opposed to methods that must be overridden.

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 by reading the B027 rule and its documentation to understand how empty methods in abstract base classes are currently handled. Determine whether the requested behavior needs a configurable rule change or only an explanation, and define done as documented, tested behavior for methods with intentional no-op defaults.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.