Repository: asottile/pyupgrade

Issue:
"".join(shlex.quote(...) ...) to shlex.join(...) is too eager
Consider the following:

```
import shlex

trash_bin = "garbage".join(shlex.quote(a) for a in ["some", "quotable strings"])
```

If I run `pyupgrade --py310-plus` on this, I get `trash_bin = shlex.join(["some", "quotable strings"])`. But this is not equivalent. This is a very contrived case, but there are real cases I could envision,  like `", "`, where one might want to keep the `str.join` 



pyupgrade==3.15.1

Discussion:

Patch:
diff --git a/pyupgrade/_plugins/shlex_join.py b/pyupgrade/_plugins/shlex_join.py
index 1406756..1718ff9 100644
--- a/pyupgrade/_plugins/shlex_join.py
+++ b/pyupgrade/_plugins/shlex_join.py
@@ -39,7 +39,7 @@ def visit_Call(
     if (
             isinstance(node.func, ast.Attribute) and
             isinstance(node.func.value, ast.Constant) and
-            isinstance(node.func.value.value, str) and
+            node.func.value.value == ' ' and
             node.func.attr == 'join' and
             not node.keywords and
             len(node.args) == 1 and


Test patch:
diff --git a/tests/features/shlex_join_test.py b/tests/features/shlex_join_test.py
index fc6abe5..e3835f6 100644
--- a/tests/features/shlex_join_test.py
+++ b/tests/features/shlex_join_test.py
@@ -15,6 +15,12 @@ from pyupgrade._main import _fix_plugins
             (3, 8),
             id='quote from-imported',
         ),
+        pytest.param(
+            'import shlex\n'
+            '"wat".join(shlex.quote(arg) for arg in cmd)\n',
+            (3, 8),
+            id='not joined with space',
+        ),
         pytest.param(
             'import shlex\n'
             '" ".join(shlex.quote(arg) for arg in cmd)\n',