From d560e38697352bcf1f0daac458f306aebc24dcd3 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 24 Mar 2024 13:02:21 -0400 Subject: [PATCH] only replace to shlex.join if joined with a space --- pyupgrade/_plugins/shlex_join.py | 2 +- tests/features/shlex_join_test.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pyupgrade/_plugins/shlex_join.py b/pyupgrade/_plugins/shlex_join.py index 14067560..1718ff9a 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 diff --git a/tests/features/shlex_join_test.py b/tests/features/shlex_join_test.py index fc6abe59..e3835f65 100644 --- a/tests/features/shlex_join_test.py +++ b/tests/features/shlex_join_test.py @@ -15,6 +15,12 @@ (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',