Skip to content

Commit 13d95f0

Browse files
committed
wording & move type-check post empty check
1 parent bd6a959 commit 13d95f0

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

Lib/shlex.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,12 @@ def join(split_command):
319319

320320
def quote(s):
321321
"""Return a shell-escaped version of the string *s*."""
322-
if not isinstance(s, str):
323-
raise TypeError(f"expected string object, got {type(s).__name__!r}")
324-
325322
if not s:
326323
return "''"
327324

325+
if not isinstance(s, str):
326+
raise TypeError(f"expected string object, got {type(s).__name__!r}")
327+
328328
# Use bytes.translate() for performance
329329
safe_chars = (b'%+,-./0123456789:=@'
330330
b'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'

Lib/test/test_shlex.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ def testQuote(self):
330330
unsafe = '"`$\\!' + unicode_sample
331331

332332
self.assertEqual(shlex.quote(''), "''")
333+
self.assertEqual(shlex.quote(None), "''")
333334
self.assertEqual(shlex.quote(safeunquoted), safeunquoted)
334335
self.assertEqual(shlex.quote('test file name'), "'test file name'")
335336
for u in unsafe:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Raise :exc:`TypeError` instead of :exc:`AttributeError` when an argument of
22
incorrect type is passed to :func:`shlex.quote`. This restores the behavior of
3-
that function pre-3.14.
3+
the function prior to 3.14.

0 commit comments

Comments
 (0)