Skip to content

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

@jakkdl

Description

@jakkdl
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions