GitHub CopilotWrite better code with AI | MCP RegistryIntegrate external tools | ActionsAutomate any workflow | CodespacesInstant dev environments | IssuesPlan and track work | Code ReviewManage code changes | Code QualityEnforce quality at merge | Why GitHub | Marketplace | View all features | Enterprises | Small and medium teams | Startups | View all use cases | View all industries | View all solutions | AI | Software Development | DevOps | Security | View all topics | Customer stories | Events & webinars | Ebooks & reports | Business insights | Trust center | Partners | View all resources
Original file line numberDiff line numberDiff line change@@ -36,6 +36,9 @@ The :mod:`shlex` module defines the following functions:
3636 instance, passing ``None`` for *s* will read the string to split from
3737 standard input.
383839+ .. deprecated:: 3.9
40+ Passing ``None`` for *s* will raise an exception in future Python
41+ versions.
39424043.. function:: join(split_command)
4144Original file line numberDiff line numberDiff line change@@ -624,6 +624,9 @@ Deprecated
624624 by :c:func:`Py_Initialize()` since Python 3.7.
625625 (Contributed by Victor Stinner in :issue:`39877`.)
626626627+* Passing ``None`` as the first argument to the :func:`shlex.split` function
628+ has been deprecated. (Contributed by Zackery Spytz in :issue:`33262`.)
629+627630628631Removed
629632=======
Original file line numberDiff line numberDiff line change@@ -304,6 +304,10 @@ def __next__(self):
304304305305defsplit(s, comments=False, posix=True):
306306"""Split the string *s* using shell-like syntax."""
307+ifsisNone:
308+importwarnings
309+warnings.warn("Passing None for 's' to shlex.split() is deprecated.",
310+DeprecationWarning, stacklevel=2)
307311lex=shlex(s, posix=posix)
308312lex.whitespace_split=True
309313ifnotcomments:
Original file line numberDiff line numberDiff line change@@ -3,7 +3,7 @@
33importshlex
44importstring
55importunittest
6-6+fromunittestimportmock
778899# The original test data set was from shellwords, by Hartmut Goebel.
@@ -162,6 +162,11 @@ def oldSplit(self, s):
162162tok=lex.get_token()
163163returnret
[email protected]('sys.stdin', io.StringIO())
166+deftestSplitNoneDeprecation(self):
167+withself.assertWarns(DeprecationWarning):
168+shlex.split(None)
169+165170deftestSplitPosix(self):
166171"""Test data splitting with posix parser"""
167172self.splitTest(self.posix_data, comments=True)
Original file line numberDiff line numberDiff line change@@ -0,0 +1,2 @@
1+Deprecate passing None as an argument for :func:`shlex.split()`'s ``s``
2+parameter. Patch by Zackery Spytz.