8000 bpo-33422: Fix quotation marks getting deleted when looking up byte/s… · python/cpython@0ba812b · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ba812b

Browse files
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 b2043bb) Co-authored-by: Andrés Delfino <adelfino@gmail.com>
1 parent eb5abdc commit 0ba812b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Lib/pydoc.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,8 +1716,9 @@ class Helper:
17161716
}
17171717
# Either add symbols to this dictionary or to the symbols dictionary
17181718
# directly: Whichever is easier. They are merged later.
1719+
_strprefixes = [p + q for p in ('b', 'f', 'r', 'u') for q in ("'", '"')]
17191720
_symbols_inverse = {
1720-
'STRINGS' : ("'", "'''", "r'", "b'", '"""', '"', 'r"', 'b"'),
1721+
'STRINGS' : ("'", "'''", '"', '"""', *_strprefixes),
17211722
'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&',
17221723
'|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'),
17231724
'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'),
@@ -1874,7 +1875,13 @@ def interact(self):
18741875
if not request: break
18751876
except (KeyboardInterrupt, EOFError):
18761877
break
1877-
request = replace(request, '"', '', "'", '').strip()
1878+
request = request.strip()
1879+
1880+
# Make sure significant trailing quoting marks of literals don't
1881+
# get deleted while cleaning input
1882+
if (len(request) > 2 and request[0] == request[-1] in ("'", '"')
1883+
and request[0] not in request[1:-1]):
1884+
request = request[1:-1]
18781885
if request.lower() in ('q', 'quit'): break
18791886
if request == 'help':
18801887
self.intro()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix trailing quotation marks getting deleted when looking up byte/string
2+
literals on pydoc. Patch by Andrés Delfino.

0 commit comments

Comments
 (0)
0