From 502683519b65f5f06026841bbd4b94b502405ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Sat, 5 May 2018 13:07:32 -0300 Subject: [PATCH 1/5] [2.7] bpo-33422: Fix quotation marks getting deleted when looking up byte/string literals on pydoc. (GH-6701) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also update the list of string prefixes.. (cherry picked from commit b2043bbe6034b53f5ad337887f4741b74b70b00d) Co-authored-by: Andrés Delfino --- Lib/pydoc.py | 7 +++++-- .../next/Library/2018-05-05-09-53-05.bpo-33422.4FtQ0q.rst | 2 ++ 2 files changed, 7 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 b4b190f3f9a6597..c5c470d5fcb8278 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 = [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,9 @@ def interact(self): if not request: break except (KeyboardInterrupt, EOFError): break - request = strip(replace(request, '"', '', "'", '')) ++ 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 000000000000000..0d284d508f1061f --- /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. From 4a9541b122bece45946da4b9385e828792bdfc7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Sat, 5 May 2018 20:15:45 -0300 Subject: [PATCH 2/5] No unpacking on 2.x :'( --- Lib/pydoc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index c5c470d5fcb8278..f1250eb42c0c921 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1649,7 +1649,7 @@ class Helper: # directly: Whichever is easier. They are merged later. _strprefixes = [p + q for p in ('b', 'r', 'u') for q in ("'", '"')] _symbols_inverse = { - 'STRINGS' : ("'", "'''", '"""', '"', *_strprefixes), + 'STRINGS' : ("'", "'''", '"""', '"') + tuple(_strprefixes), 'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&', '|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'), 'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'), From 840c1b017dab4c2521f6f65553ca1af8e78505a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Sat, 5 May 2018 20:29:22 -0300 Subject: [PATCH 3/5] Fix --- Lib/pydoc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index f1250eb42c0c921..561cc79179d9ea1 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1812,9 +1812,9 @@ def interact(self): if not request: break except (KeyboardInterrupt, EOFError): break -+ if (len(request) > 2 and request[0] == request[-1] in ("'", '"') -+ and request[0] not in request[1:-1]): -+ request = request[1:-1] + 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) From acf9d32aea9c190179a5392ded779b5b7b9509b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Sun, 6 May 2018 08:56:55 -0300 Subject: [PATCH 4/5] strip request and add comment --- Lib/pydoc.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 561cc79179d9ea1..3d7c0b27c8fe89a 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1812,6 +1812,9 @@ def interact(self): if not request: break except (KeyboardInterrupt, EOFError): break + 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] From 2ad318d3fed1598419a71e4c941152cf72f86827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Sun, 6 May 2018 12:52:16 -0300 Subject: [PATCH 5/5] Use generator expression instead of list display --- Lib/pydoc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 3d7c0b27c8fe89a..62cc262ccb83ff1 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1647,9 +1647,9 @@ class Helper: } # Either add symbols to this dictionary or to the symbols dictionary # directly: Whichever is easier. They are merged later. - _strprefixes = [p + q for p in ('b', 'r', 'u') for q in ("'", '"')] + _strprefixes = tuple(p + q for p in ('b', 'r', 'u') for q in ("'", '"')) _symbols_inverse = { - 'STRINGS' : ("'", "'''", '"""', '"') + tuple(_strprefixes), + 'STRINGS' : ("'", "'''", '"""', '"') + _strprefixes, 'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&', '|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'), 'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'),