8000 gh-94352: shlex.split() no longer accepts None (#94353) · python/cpython@fbcee57 · GitHub
[go: up one dir, main page]

Skip to content

Commit fbcee57

Browse files
authored
gh-94352: shlex.split() no longer accepts None (#94353)
shlex.split(): Passing None for s argument now raises an exception, rather than reading sys.stdin. The feature was deprecated in Python 3.9.
1 parent 670f7f1 commit fbcee57

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

Doc/library/shlex.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ The :mod:`shlex` module defines the following functions:
3636
instance, passing ``None`` for *s* will read the string to split from
3737
standard input.
3838

39-
.. deprecated:: 3.9
40-
Passing ``None`` for *s* will raise an exception in future Python
41-
versions.
39+
.. versionchanged:: 3.12
40+
Passing ``None`` for *s* argument now raises an exception, rather than
41+
reading :data:`sys.stdin`.
4242

4343
.. function:: join(split_command)
4444

Doc/whatsnew/3.12.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ Changes in the Python API
324324
to :term:`filesystem encoding and error handler`.
325325
Argument files should be encoded in UTF-8 instead of ANSI Codepage on Windows.
326326

327+
* :func:`shlex.split`: Passing ``None`` for *s* argument now raises an
328+
exception, rather than reading :data:`sys.stdin`. The feature was deprecated
329+
in Python 3.9.
330+
(Contributed by Victor Stinner in :gh:`94352`.)
331+
327332

328333
Build Changes
329334
=============

Lib/shlex.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,7 @@ def __next__(self):
305305
def split(s, comments=False, posix=True):
306306
"""Split the string *s* using shell-like syntax."""
307307
if s is None:
308-
import warnings
309-
warnings.warn("Passing None for 's' to shlex.split() is deprecated.",
310-
DeprecationWarning, stacklevel=2)
308+
raise ValueError("s argument must not be None")
311309
lex = shlex(s, posix=posix)
312310
lex.whitespace_split = True
313311
if not comments:

Lib/test/test_shlex.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ def oldSplit(self, s):
162162
tok = lex.get_token()
163163
return ret
164164

165-
@mock.patch('sys.stdin', io.StringIO())
166-
def testSplitNoneDeprecation(self):
167-
with self.assertWarns(DeprecationWarning):
165+
def testSplitNone(self):
166+
with self.assertRaises(ValueError):
168167
shlex.split(None)
169168

170169
def testSplitPosix(self):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:func:`shlex.split`: Passing ``None`` for *s* argument now raises an exception,
2+
rather than reading :data:`sys.stdin`. The feature was deprecated in Python
3+
3.9. Patch by Victor Stinner.

0 commit comments

Comments
 (0)
0