]> granicus.if.org Git - python/commitdiff
bpo-33422: Fix quotation marks getting deleted when looking up byte/string literals...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 5 May 2018 17:12:19 +0000 (10:12 -0700)
committerGitHub <noreply@github.com>
Sat, 5 May 2018 17:12:19 +0000 (10:12 -0700)
Also update the list of string prefixes.
(cherry picked from commit b2043bbe6034b53f5ad337887f4741b74b70b00d)

Co-authored-by: Andrés Delfino <adelfino@gmail.com>
Lib/pydoc.py
Misc/NEWS.d/next/Library/2018-05-05-09-53-05.bpo-33422.4FtQ0q.rst [new file with mode: 0644]

index 34e2fabf20ee0647e8325a04a0fd093208ba50d9..40ee76044089437e72673da0072efcae9bd2abdd 100644 (file)
@@ -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 @@ has the same effect as typing a particular string at the help> prompt.
                 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 (file)
index 0000000..0d284d5
--- /dev/null
@@ -0,0 +1,2 @@
+Fix trailing quotation marks getting deleted when looking up byte/string
+literals on pydoc. Patch by Andrés Delfino.