PyCQA / PyCQA/flake8-bugbear

B006: Case where mutable default arguments are not detected

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

Nobody has claimed this yet.

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

Description

I realized that when using Python built-in dataclasses, the following scenario is not detected:

from dataclasses import dataclass

@dataclass
class MyClass:
    val = []  # Mutable data structure

Given the presence of the dataclass decorator, the signature of the __init__ method for MyClass is the following one:

def __init__(self, val = []):

I have seen that the rule B006 is supposed to detect issues where mutable data structures are used in a function signature. This is a slightly different scenario but with the same output if this effect is not intended.
I could not find any related issue. Was this issue reported before?

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 reproducing the dataclass example from the issue and inspect the implementation and tests for rule B006. Determine whether class attributes in dataclasses are intended to receive the same warning as mutable function defaults, then add coverage and update the rule only if that behavior is confirmed.

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
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.