mirror of
https://github.com/python/cpython.git
synced 2025-10-18 04:38:07 +00:00
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.
This commit is contained in:
parent
670f7f10cf
commit
fbcee570d1
5 changed files with 14 additions and 9 deletions
|
@ -36,9 +36,9 @@ The :mod:`shlex` module defines the following functions:
|
||||||
instance, passing ``None`` for *s* will read the string to split from
|
instance, passing ``None`` for *s* will read the string to split from
|
||||||
standard input.
|
standard input.
|
||||||
|
|
||||||
.. deprecated:: 3.9
|
.. versionchanged:: 3.12
|
||||||
Passing ``None`` for *s* will raise an exception in future Python
|
Passing ``None`` for *s* argument now raises an exception, rather than
|
||||||
versions.
|
reading :data:`sys.stdin`.
|
||||||
|
|
||||||
.. function:: join(split_command)
|
.. function:: join(split_command)
|
||||||
|
|
||||||
|
|
|
@ -324,6 +324,11 @@ Changes in the Python API
|
||||||
to :term:`filesystem encoding and error handler`.
|
to :term:`filesystem encoding and error handler`.
|
||||||
Argument files should be encoded in UTF-8 instead of ANSI Codepage on Windows.
|
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
|
Build Changes
|
||||||
=============
|
=============
|
||||||
|
|
|
@ -305,9 +305,7 @@ class shlex:
|
||||||
def split(s, comments=False, posix=True):
|
def split(s, comments=False, posix=True):
|
||||||
"""Split the string *s* using shell-like syntax."""
|
"""Split the string *s* using shell-like syntax."""
|
||||||
if s is None:
|
if s is None:
|
||||||
import warnings
|
raise ValueError("s argument must not be None")
|
||||||
warnings.warn("Passing None for 's' to shlex.split() is deprecated.",
|
|
||||||
DeprecationWarning, stacklevel=2)
|
|
||||||
lex = shlex(s, posix=posix)
|
lex = shlex(s, posix=posix)
|
||||||
lex.whitespace_split = True
|
lex.whitespace_split = True
|
||||||
if not comments:
|
if not comments:
|
||||||
|
|
|
@ -162,9 +162,8 @@ class ShlexTest(unittest.TestCase):
|
||||||
tok = lex.get_token()
|
tok = lex.get_token()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@mock.patch('sys.stdin', io.StringIO())
|
def testSplitNone(self):
|
||||||
def testSplitNoneDeprecation(self):
|
with self.assertRaises(ValueError):
|
||||||
with self.assertWarns(DeprecationWarning):
|
|
||||||
shlex.split(None)
|
shlex.split(None)
|
||||||
|
|
||||||
def testSplitPosix(self):
|
def testSplitPosix(self):
|
||||||
|
|
|
@ -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.
|
Loading…
Add table
Add a link
Reference in a new issue