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

Skip to content

Commit b2043bb

Browse files
andresdelfinoserhiy-storchaka
authored andcommitted
bpo-33422: Fix quotation marks getting deleted when looking up byte/string literals on pydoc. (GH-6701)
Also update the list of string prefixes.
1 parent c4994dc commit b2043bb

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
@@ -1747,8 +1747,9 @@ class Helper:
17471747
}
17481748
# Either add symbols to this dictionary or to the symbols dictionary
17491749
# directly: Whichever is easier. They are merged later.
1750+
_strprefixes = [p + q for p in ('b', 'f', 'r', 'u') for q in ("'", '"')]
17501751
_symbols_inverse = {
1751-
'STRINGS' : ("'", "'''", "r'", "b'", '"""', '"', 'r"', 'b"'),
1752+
'STRINGS' : ("'", "'''", '"', '"""', *_strprefixes),
17521753
'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&',
17531754
'|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'),
17541755
'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'),
@@ -1910,7 +1911,13 @@ def interact(self):
19101911
if not request: break
19111912
except (KeyboardInterrupt, EOFError):
19121913
break
1913-
request = replace(request, '"', '', "'", '').strip()
1914+
request = request.strip()
1915+
1916+
# Make sure significant trailing quoting marks of literals don't
1917+
# get deleted while cleaning input
1918+
if (len(request) > 2 and request[0] == request[-1] in ("'", '"')
1919+
and request[0] not in request[1:-1]):
1920+
request = request[1:-1]
19141921
if request.lower() in ('q', 'quit'): break
19151922
if request == 'help':
19161923
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