From c40eeeb5e69df12a5f46edc7ba82ec75c7d1b820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Mon, 7 May 2018 02:44:03 -0300 Subject: [PATCH] [2.7] bpo-33422: Fix quotation marks getting deleted when looking up byte/string literals on pydoc. (GH-6701) (GH-6712) Also update the list of string prefixes. (cherry picked from commit b2043bbe6034b53f5ad337887f4741b74b70b00d) --- Lib/pydoc.py | 10 ++++++++-- .../Library/2018-05-05-09-53-05.bpo-33422.4FtQ0q.rst | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2018-05-05-09-53-05.bpo-33422.4FtQ0q.rst diff --git a/Lib/pydoc.py b/Lib/pydoc.py index b4b190f3f9a..62cc262ccb8 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1647,8 +1647,9 @@ class Helper: } # Either add symbols to this dictionary or to the symbols dictionary # directly: Whichever is easier. They are merged later. + _strprefixes = tuple(p + q for p in ('b', 'r', 'u') for q in ("'", '"')) _symbols_inverse = { - 'STRINGS' : ("'", "'''", "r'", "u'", '"""', '"', 'r"', 'u"'), + 'STRINGS' : ("'", "'''", '"""', '"') + _strprefixes, 'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&', '|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'), 'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'), @@ -1811,7 +1812,12 @@ has the same effect as typing a particular string at the help> prompt. if not request: break except (KeyboardInterrupt, EOFError): break - request = strip(replace(request, '"', '', "'", '')) + request = strip(request) + # Make sure significant trailing quotation marks of literals don't + # get deleted while cleaning input + if (len(request) > 2 and request[0] == request[-1] in ("'", '"') + and request[0] not in request[1:-1]): + request = request[1:-1] if lower(request) in ('q', 'quit'): break self.help(request) diff --git a/Misc/NEWS.d/next/Library/2018-05-05-09-53-05.bpo-33422.4FtQ0q.rst b/Misc/NEWS.d/next/Library/2018-05-05-09-53-05.bpo-33422.4FtQ0q.rst new file mode 100644 index 00000000000..0d284d508f1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-05-05-09-53-05.bpo-33422.4FtQ0q.rst @@ -0,0 +1,2 @@ +Fix trailing quotation marks getting deleted when looking up byte/string +literals on pydoc. Patch by Andrés Delfino.