Skip to content

Commit 58eef72

Browse files
kovanclaude
andcommitted
gh-142895: Improve shlex.join docstring
Expand the terse docstring for shlex.join() to explain that it is the inverse of split() and that the result is shell-escaped. Add doctest examples showing round-trip behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7e2c9bd commit 58eef72

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Lib/shlex.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,18 @@ def split(s, comments=False, posix=True):
313313

314314

315315
def join(split_command):
316-
"""Return a shell-escaped string from *split_command*."""
316+
"""Concatenate the tokens of the list *split_command* and return a string.
317+
318+
This is the inverse of :func:`split`: the returned value is
319+
shell-escaped to protect against injection, so the split of the
320+
result equals *split_command*.
321+
322+
>>> from shlex import split, join
323+
>>> split('echo "hello world"')
324+
['echo', 'hello world']
325+
>>> join(['echo', 'hello world'])
326+
"echo 'hello world'"
327+
"""
317328
return ' '.join(quote(arg) for arg in split_command)
318329

319330

0 commit comments

Comments
 (0)