Skip to content

Commit

Permalink
only replace to shlex.join if joined with a space
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Mar 24, 2024
1 parent 3e4103f commit d560e38
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyupgrade/_plugins/shlex_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/features/shlex_join_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit d560e38

Please sign in to comment.