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).
Summary
make_strings_unique(str_list)assignsunique_strs = str_list(an alias,not a copy) and then modifies
unique_strs[i], which silently mutatesthe original
str_listthe caller passed in. Any code that retains areference to the original list will observe unexpected changes.
Reproduction
Expected Behavior
The input should not be modified. Only the returned list should be unique.
Suggested Fix
Replace
unique_strs = str_listwithunique_strs = list(str_list).