instance, passing ``None`` for *s* will read the string to split from
standard input.
+ .. deprecated:: 3.9
+ Passing ``None`` for *s* will raise an exception in future Python
+ versions.
.. function:: join(split_command)
by :c:func:`Py_Initialize()` since Python 3.7.
(Contributed by Victor Stinner in :issue:`39877`.)
+* Passing ``None`` as the first argument to the :func:`shlex.split` function
+ has been deprecated. (Contributed by Zackery Spytz in :issue:`33262`.)
+
Removed
=======
def split(s, comments=False, posix=True):
"""Split the string *s* using shell-like syntax."""
+ if s is None:
+ import warnings
+ warnings.warn("Passing None for 's' to shlex.split() is deprecated.",
+ DeprecationWarning, stacklevel=2)
lex = shlex(s, posix=posix)
lex.whitespace_split = True
if not comments:
import shlex
import string
import unittest
-
+from unittest import mock
# The original test data set was from shellwords, by Hartmut Goebel.
tok = lex.get_token()
return ret
+ @mock.patch('sys.stdin', io.StringIO())
+ def testSplitNoneDeprecation(self):
+ with self.assertWarns(DeprecationWarning):
+ shlex.split(None)
+
def testSplitPosix(self):
"""Test data splitting with posix parser"""
self.splitTest(self.posix_data, comments=True)
--- /dev/null
+Deprecate passing None as an argument for :func:`shlex.split()`'s ``s``
+parameter. Patch by Zackery Spytz.