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
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 @@
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 shlex
import string
import unittest
-
+from unittest import mock
# The original test data set was from shellwords, by Hartmut Goebel.
@@ -162,6 +162,11 @@
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)