]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-94352: shlex.split() no longer accepts None (#94353)
authorVictor Stinner <vstinner@python.org>
Mon, 4 Jul 2022 13:29:19 +0000 (15:29 +0200)
committerGitHub <noreply@github.com>
Mon, 4 Jul 2022 13:29:19 +0000 (15:29 +0200)
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
Doc/whatsnew/3.12.rst
Lib/shlex.py
Lib/test/test_shlex.py
Misc/NEWS.d/next/Library/2022-06-28-00-24-48.gh-issue-94352.JY1Ayt.rst [new file with mode: 0644]

index aab6a54379209686e49c199eb36785eff3dd6add..0bad51833aae131f09c5a60f114b5c891d27653f 100644 (file)
@@ -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)
 
index 620aa91f6da22710c0bd1e587d087989f681b7c2..ed21abaeb6dc18da8035d9721c75a81c5ab81ce2 100644 (file)
@@ -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
 =============
index 4801a6c1d47bd9e0a8ada16089221c8237b777d5..a91c9b022627b18580e5c78c7986cf0f38f479ac 100644 (file)
@@ -305,9 +305,7 @@ class shlex:
 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:
index 3081a785204edc6ade5803ea484813095a12b914..92598dbbd5f293c46bca64026e7968030df55af1 100644 (file)
@@ -162,9 +162,8 @@ class ShlexTest(unittest.TestCase):
             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 (file)
index 0000000..3a166ab
--- /dev/null
@@ -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.