Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
bpo-33262: Deprecate passing None for s to shlex.split()
This reads the string to split from standard input.
  • Loading branch information
ZackerySpytz committed Apr 17, 2018
commit a1b35aaa3ed5a5e6395cb71bf43f2184fb5952c3
2 changes: 2 additions & 0 deletions Doc/library/shlex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ The :mod:`shlex` module defines the following functions:
instance, passing ``None`` for *s* will read the string to split from
standard input.

.. deprecated:: 3.8
Passing ``None`` for *s*.

.. function:: quote(s)

Expand Down
4 changes: 4 additions & 0 deletions Lib/shlex.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ def __next__(self):
return token

def split(s, comments=False, posix=True):
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:
Expand Down
7 changes: 6 additions & 1 deletion Lib/test/test_shlex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import shlex
import string
import unittest

from unittest import mock


# The original test data set was from shellwords, by Hartmut Goebel.
Expand Down Expand Up @@ -161,6 +161,11 @@ def oldSplit(self, s):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Deprecate passing None as an argument for :func:`shlex.split()`'s ``s``
parameter. Patch by Zackery Spytz.