[Python-checkins] bpo-33422: Fix quotation marks getting deleted when looking up byte/string literals on pydoc. (GH-6701)

Miss Islington (bot) webhook-mailer at python.org
Sat May 5 13:12:22 EDT 2018


https://github.com/python/cpython/commit/0ba812b1bee65a6cad16f153a7f5074bc271e0e5
commit: 0ba812b1bee65a6cad16f153a7f5074bc271e0e5
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-05-05T10:12:19-07:00
summary:

bpo-33422: Fix quotation marks getting deleted when looking up byte/string literals on pydoc. (GH-6701)


Also update the list of string prefixes.
(cherry picked from commit b2043bbe6034b53f5ad337887f4741b74b70b00d)

Co-authored-by: Andrés Delfino <adelfino at gmail.com>

files:
A Misc/NEWS.d/next/Library/2018-05-05-09-53-05.bpo-33422.4FtQ0q.rst
M Lib/pydoc.py

diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 34e2fabf20ee..40ee76044089 100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1716,8 +1716,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', 'f', 'r', 'u') for q in ("'", '"')]
     _symbols_inverse = {
-        'STRINGS' : ("'", "'''", "r'", "b'", '"""', '"', 'r"', 'b"'),
+        'STRINGS' : ("'", "'''", '"', '"""', *_strprefixes),
         'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&',
                        '|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'),
         'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'),
@@ -1874,7 +1875,13 @@ def interact(self):
                 if not request: break
             except (KeyboardInterrupt, EOFError):
                 break
-            request = replace(request, '"', '', "'", '').strip()
+            request = request.strip()
+
+            # Make sure significant trailing quoting 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 request.lower() in ('q', 'quit'): break
             if request == 'help':
                 self.intro()
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 000000000000..0d284d508f10
--- /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.



More information about the Python-checkins mailing list