Skip to content

[Bug] Mutable default arguments (B006) in Completions.create and BaseEmbedderConfig.__init__ #5301

@kratos0718

Description

@kratos0718

Component

Core / Python SDK

Description

Two mutable default arguments in the Python SDK — the classic anti-pattern flagged by ruff B006 and pylint W0102. The same list/dict instance is shared across every call that uses the default, so any in-place mutation leaks across calls.

Affected symbols

  • mem0/proxy/main.pyCompletions.create(messages: List = [])
  • mem0/configs/embeddings/base.pyBaseEmbedderConfig.__init__(azure_kwargs: Optional[AzureConfig] = {}) (also a type-annotation mismatch — declared Optional but defaulted to {})

Reproduction

import inspect
from mem0.proxy.main import Completions

sig = inspect.signature(Completions.create)
default = sig.parameters["messages"].default
print(type(default).__name__, id(default))
# list 0x... — a single module-level instance shared across every call
Expected behavior
Each call should receive its own fresh [] / {}, isolated from other calls.

Environment
N/Acode-quality bug, environment-independent (Python 3.10+ source).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions