summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2020-04-01 13:58:55 (GMT)
committerGitHub <noreply@github.com>2020-04-01 13:58:55 (GMT)
commit975ac326ffe265e63a103014fd27e9d098fe7548 (patch)
treeb8a86b68b758d9bf11df94b70735fe5981ed49b3
parent7c72383f95b0cdedf390726069428d7b69ed2597 (diff)
downloadcpython-975ac326ffe265e63a103014fd27e9d098fe7548.zip
cpython-975ac326ffe265e63a103014fd27e9d098fe7548.tar.gz
cpython-975ac326ffe265e63a103014fd27e9d098fe7548.tar.bz2
bpo-33262: Deprecate passing None for `s` to shlex.split() (GH-6514)
* bpo-33262: Deprecate passing None for `s` to shlex.split() This reads the string to split from standard input. * Update What's New. * Fix shlex.rst
-rw-r--r--Doc/library/shlex.rst3
-rw-r--r--Doc/whatsnew/3.9.rst3
-rw-r--r--Lib/shlex.py4
-rw-r--r--Lib/test/test_shlex.py7
-rw-r--r--Misc/NEWS.d/next/Library/2018-04-17-13-23-29.bpo-33262.vHC7YQ.rst2
5 files changed, 18 insertions, 1 deletions
diff --git a/Doc/library/shlex.rst b/Doc/library/shlex.rst
index adc23da..7f7f0c7 100644
--- a/Doc/library/shlex.rst
+++ b/Doc/library/shlex.rst
@@ -36,6 +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.
.. function:: join(split_command)
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index 59083da..6ea4ad8 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -624,6 +624,9 @@ Deprecated
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
=======
diff --git a/Lib/shlex.py b/Lib/shlex.py
index c817274..4801a6c 100644
--- a/Lib/shlex.py
+++ b/Lib/shlex.py
@@ -304,6 +304,10 @@ 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)
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 a21ccd2..3081a78 100644
--- a/Lib/test/test_shlex.py
+++ b/Lib/test/test_shlex.py
@@ -3,7 +3,7 @@ import itertools
import shlex
import string
import unittest
-
+from unittest import mock
# The original test data set was from shellwords, by Hartmut Goebel.
@@ -162,6 +162,11 @@ class ShlexTest(unittest.TestCase):
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)
diff --git a/Misc/NEWS.d/next/Library/2018-04-17-13-23-29.bpo-33262.vHC7YQ.rst b/Misc/NEWS.d/next/Library/2018-04-17-13-23-29.bpo-33262.vHC7YQ.rst
new file mode 100644
index 0000000..2afe13a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-04-17-13-23-29.bpo-33262.vHC7YQ.rst
@@ -0,0 +1,2 @@
+Deprecate passing None as an argument for :func:`shlex.split()`'s ``s``
+parameter. Patch by Zackery Spytz.