This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: shlex constructor unreachable code
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Michael.Smith, abarnert, berker.peksag, python-dev
Priority: low Keywords: easy

Created on 2015-05-02 13:41 by Michael.Smith, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg242399 - (view) Author: Michael Smith (Michael.Smith) Date: 2015-05-02 13:41
In its __init__ method, shlex.shlex sets self.debug = 0. An `if self.debug:` statement follows shortly thereafter and without allowing the user to change self.debug.

The code inside the if statement is unreachable. Users should either be permitted to set debug on via an optional __init__ parameter, or debug should be taken out of the initializer altogether.
msg242400 - (view) Author: Michael Smith (Michael.Smith) Date: 2015-05-02 13:43
Hat tip abarnert on StackOverflow for digging in.

http://stackoverflow.com/questions/29996208/putting-shlex-in-debug-mode

This code was introduced in https://hg.python.org/cpython/rev/81a121d21340
msg242497 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-05-03 18:11
Thanks for the report.

> Users should either be permitted to set debug on via an optional __init__ parameter,

This is already possible via the debug attribute (https://docs.python.org/3/library/shlex.html#shlex.shlex.debug), so I don't think adding a debug parameter to __init__ is necessary.

> or debug should be taken out of the initializer altogether.

+1. We can just remove the unreachable code.
msg242527 - (view) Author: Andrew Barnert (abarnert) * Date: 2015-05-03 21:33
Presumably ESR thought that information was useful enough to send Guido a patch to add it. But apparently nobody's missed it in the 15 years it's been checked in but unreachable. If anyone needed to know the `instream` and `lineno` right after initialization, presumably they just printed them directly. So, yeah, seems unnecessary to me.
msg242587 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-05-05 02:45
New changeset 395e190ead36 by Raymond Hettinger in branch 'default':
Issue #24113:  Remove unreachable code in shlex.
https://hg.python.org/cpython/rev/395e190ead36
History
Date User Action Args
2022-04-11 14:58:16adminsetgithub: 68301
2015-05-05 02:51:45berker.peksagsetstage: needs patch -> resolved
2015-05-05 02:46:39rhettingersetpriority: normal -> low
status: open -> closed
resolution: fixed
2015-05-05 02:45:57python-devsetnosy: + python-dev
messages: + msg242587
2015-05-03 21:33:26abarnertsetnosy: + abarnert
messages: + msg242527
2015-05-03 18:11:06berker.peksagsettype: behavior -> enhancement
versions: - Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.6
keywords: + easy
nosy: + berker.peksag

messages: + msg242497
stage: needs patch
2015-05-02 13:44:00Michael.Smithsetmessages: + msg242400
2015-05-02 13:41:50Michael.Smithcreate