Skip to content

SIM905 fix is incorrect for unpacked dict arguments #18101

@ntBre

Description

@ntBre

Summary

While reviewing #17454 just after reviewing #18075, I realized that the split-static-string (SIM905) fix breaks when **kwargs are passed to split:

> cat <<EOF | ruff check --select SIM905 --diff -
d = {"sep": ","}

"a,b,c,d".split(**{"sep": ","})
"a,b,c,d".split(**d)
EOF
@@ -1,4 +1,4 @@
 d = {"sep": ","}

-"a,b,c,d".split(**{"sep": ","})
-"a,b,c,d".split(**d)
+["a,b,c,d"]
+["a,b,c,d"]

Would fix 2 errors.

The same code in Python produces ['a', 'b', 'c', 'd'] instead of ['a,b,c,d'].

I think the root cause here is that find_argument_value doesn't (or possibly can't) resolve the starred argument, so this might affect any rule that uses it.

Shoutout to @vjurczenia whose careful dict handling in #17454 brought this to my attention.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-designNeeds further design before implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions