8000 gh-94352: shlex.split() no longer accepts None by vstinner · Pull Request #94353 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-94352: shlex.split() no longer accepts None #94353

New issue 8000

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Doc/library/shlex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============
Expand Down
4 changes: 1 addition & 3 deletions Lib/shlex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions Lib/test/test_shlex.py
A323
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
0