bpo-33262: Deprecate passing None for s
to shlex.split() (GH-6514) · python/cpython@975ac32 (original) (raw)
5 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -36,6 +36,9 @@ The :mod:`shlex` module defines the following functions: | ||
36 | 36 | instance, passing ``None`` for *s* will read the string to split from |
37 | 37 | standard input. |
38 | 38 | |
39 | + .. deprecated:: 3.9 | |
40 | + Passing ``None`` for *s* will raise an exception in future Python | |
41 | + versions. | |
39 | 42 | |
40 | 43 | .. function:: join(split_command) |
41 | 44 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -624,6 +624,9 @@ Deprecated | ||
624 | 624 | by :c:func:`Py_Initialize()` since Python 3.7. |
625 | 625 | (Contributed by Victor Stinner in :issue:`39877`.) |
626 | 626 | |
627 | +* Passing ``None`` as the first argument to the :func:`shlex.split` function | |
628 | + has been deprecated. (Contributed by Zackery Spytz in :issue:`33262`.) | |
629 | + | |
627 | 630 | |
628 | 631 | Removed |
629 | 632 | ======= |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -304,6 +304,10 @@ def __next__(self): | ||
304 | 304 | |
305 | 305 | def split(s, comments=False, posix=True): |
306 | 306 | """Split the string *s* using shell-like syntax.""" |
307 | +if s is None: | |
308 | +import warnings | |
309 | +warnings.warn("Passing None for 's' to shlex.split() is deprecated.", | |
310 | +DeprecationWarning, stacklevel=2) | |
307 | 311 | lex = shlex(s, posix=posix) |
308 | 312 | lex.whitespace_split = True |
309 | 313 | if not comments: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3,7 +3,7 @@ | ||
3 | 3 | import shlex |
4 | 4 | import string |
5 | 5 | import unittest |
6 | - | |
6 | +from unittest import mock | |
7 | 7 | |
8 | 8 | |
9 | 9 | # The original test data set was from shellwords, by Hartmut Goebel. |
@@ -162,6 +162,11 @@ def oldSplit(self, s): | ||
162 | 162 | tok = lex.get_token() |
163 | 163 | return ret |
164 | 164 | |
165 | +@mock.patch('sys.stdin', io.StringIO()) | |
166 | +def testSplitNoneDeprecation(self): | |
167 | +with self.assertWarns(DeprecationWarning): | |
168 | +shlex.split(None) | |
169 | + | |
165 | 170 | def testSplitPosix(self): |
166 | 171 | """Test data splitting with posix parser""" |
167 | 172 | self.splitTest(self.posix_data, comments=True) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1 | +Deprecate passing None as an argument for :func:`shlex.split()`'s ``s`` | |
2 | +parameter. Patch by Zackery Spytz. |