Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 5, 2026

Python's mutable default arguments are evaluated once at function definition and shared across all calls, causing unintended state pollution. Seven functions used dict = {} as defaults.

Changes

  • wrangles/utils.py: evaluate_conditional(), safe_str_transform()
  • wrangles/recipe_wrangles/split.py: dictionary()
  • wrangles/recipe_wrangles/convert.py: _getSentenceCase()
  • wrangles/connectors/test.py: read()
  • wrangles/connectors/train.py: lookup.write()
  • wrangles/connectors/mongodb.py: read()

Pattern Applied

# Before
def read(rows: int, values: dict = {}) -> pd.DataFrame:
    data = {}
    for key, val in values.items():
        data[key] = generate_values(val, rows)
    return pd.DataFrame(data)

# After
def read(rows: int, values: dict = None) -> pd.DataFrame:
    if values is None:
        values = {}
    data = {}
    for key, val in values.items():
        data[key] = generate_values(val, rows)
    return pd.DataFrame(data)

Each function now uses None as default with explicit initialization, preventing cross-call state leakage.

Original prompt

please work on issue 796 (dictioanry defaults)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: ebhills <53243273+ebhills@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix dictionary defaults in issue 796 Fix mutable default arguments across function signatures Jan 5, 2026
Copilot AI requested a review from ebhills January 5, 2026 16:07
@ebhills ebhills linked an issue Jan 5, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix dictionary defaults

2 participants