Skip to content

make_strings_unique mutates the caller's input list in-place instead of returning a modified copy #551

@vedant21-oss

Description

@vedant21-oss

Summary

make_strings_unique(str_list) assigns unique_strs = str_list (an alias,
not a copy) and then modifies unique_strs[i], which silently mutates
the original str_list the caller passed in. Any code that retains a
reference to the original list will observe unexpected changes.

Reproduction

from skbase.utils._iter import make_strings_unique
names = ["a", "a", "b"]
result = make_strings_unique(names)
print(names)   # ['a_1', 'a_2', 'b'] -- original was mutated!

Expected Behavior

The input should not be modified. Only the returned list should be unique.

Suggested Fix

Replace unique_strs = str_list with unique_strs = list(str_list).

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