PyCQA / flake8-bugbear

A plugin for Flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle.
MIT License
1.05k stars 103 forks source link

Feature Request: expand B006 and B008 to also cover `ContextVar` defaults #475

Closed jakkdl closed 1 week ago

jakkdl commented 2 weeks ago
from contextvars import ContextVar, copy_context

cv: ContextVar[list[int]] = ContextVar("cv", default=[])

def append_to_cv_list():
    cv.get().append(0)

ctx = copy_context()
ctx.run(append_to_cv_list)
ctx.run(append_to_cv_list)
print(cv.get())

This will print [0, 0] instead of the expected [], very similar to B006 and B008. Can either raise B006 & B008, or just reuse their machinery but raise a new error code.