Skip to content

Fix mutable default arguments in core and plugins #197

Description

@stef41

Description

14 function signatures across 9 files use mutable default arguments (=[], ={}), which is a well-known Python anti-pattern.

Mutable defaults are evaluated once at function definition time and shared across all calls, so data from one invocation can silently persist into subsequent calls. This is particularly concerning in the AI reasoning interfaces where shared state between invocations could lead to subtle bugs.

Proposed Fix

Replace all mutable defaults with None sentinels and assign fresh instances inside the function body:

# Before
def foo(items=[]):
    items.append(1)
    return items

# After  
def foo(items=None):
    if items is None:
        items = []
    items.append(1)
    return items

Files Affected

  • onair/src/reasoning/reasoning_interface.py
  • onair/src/reasoning/agent.py
  • And 7 additional files in onair/src/ and plugins

PR

PR #194 addresses this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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