From 91dda4bff8f0cb19eaf6fa93fed0efc44a727260 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 28 Jun 2022 00:24:50 +0200 Subject: [PATCH] gh-94352: shlex.split() no longer accepts None shlex.split(): Passing None for s argument now raises an exception, rather than reading sys.stdin. The feature was deprecated in Python 3.9. --- Doc/library/shlex.rst | 6 +++--- Doc/whatsnew/3.12.rst | 5 +++++ Lib/shlex.py | 4 +--- Lib/test/test_shlex.py | 5 ++--- .../Library/2022-06-28-00-24-48.gh-issue-94352.JY1Ayt.rst | 3 +++ 5 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-06-28-00-24-48.gh-issue-94352.JY1Ayt.rst diff --git a/Doc/library/shlex.rst b/Doc/library/shlex.rst index aab6a543792096..0bad51833aae13 100644 --- a/Doc/library/shlex.rst +++ b/Doc/library/shlex.rst @@ -36,9 +36,9 @@ The :mod:`shlex` module defines the following functions: 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. + .. versionchanged:: 3.12 + Passing ``None`` for *s* argument now raises an exception, rather than + reading :data:`sys.stdin`. .. function:: join(split_command) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 620aa91f6da227..ed21abaeb6dc18 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -324,6 +324,11 @@ Changes in the Python API to :term:`filesystem encoding and error handler`. Argument files should be encoded in UTF-8 instead of ANSI Codepage on Windows. +* :func:`shlex.split`: Passing ``None`` for *s* argument now raises an + exception, rather than reading :data:`sys.stdin`. The feature was deprecated + in Python 3.9. + (Contributed by Victor Stinner in :gh:`94352`.) + Build Changes ============= diff --git a/Lib/shlex.py b/Lib/shlex.py index 4801a6c1d47bd9..a91c9b022627b1 100644 --- a/Lib/shlex.py +++ b/Lib/shlex.py @@ -305,9 +305,7 @@ def __next__(self): 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) + raise ValueError("s argument must not be None") lex = shlex(s, posix=posix) lex.whitespace_split = True if not comments: diff --git a/Lib/test/test_shlex.py b/Lib/test/test_shlex.py index 3081a785204edc..92598dbbd5f293 100644 --- a/Lib/test/test_shlex.py +++ b/Lib/test/test_shlex.py @@ -162,9 +162,8 @@ def oldSplit(self, s): tok = lex.get_token() return ret - @mock.patch('sys.stdin', io.StringIO()) - def testSplitNoneDeprecation(self): - with self.assertWarns(DeprecationWarning): + def testSplitNone(self): + with self.assertRaises(ValueError): shlex.split(None) def testSplitPosix(self): diff --git a/Misc/NEWS.d/next/Library/2022-06-28-00-24-48.gh-issue-94352.JY1Ayt.rst b/Misc/NEWS.d/next/Library/2022-06-28-00-24-48.gh-issue-94352.JY1Ayt.rst new file mode 100644 index 00000000000000..3a166abdcc3203 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-06-28-00-24-48.gh-issue-94352.JY1Ayt.rst @@ -0,0 +1,3 @@ +:func:`shlex.split`: Passing ``None`` for *s* argument now raises an exception, +rather than reading :data:`sys.stdin`. The feature was deprecated in Python +3.9. Patch by Victor Stinner.