-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-33422: Consider the special case of string/byte literals, and update the lis… #6701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-33422: Consider the special case of string/byte literals, and update the lis… #6701
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a news entry. This PR fixes a real bug in stripping quotes in the interactive help.
Lib/pydoc.py
Outdated
@@ -1910,7 +1911,11 @@ def interact(self): | |||
if not request: break | |||
except (KeyboardInterrupt, EOFError): | |||
break | |||
request = replace(request, '"', '', "'", '').strip() | |||
request = request.strip() | |||
if not (len(request) == 2 and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to replace the code with:
if (len(request) > 2 and request[0] == request[-1] in ("'", '"')
and request[0] not in request[1:-1]):
request = request[1:-1]
(and add a comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's okay to keep a quotation mark in cases like:
"spam
eggs"
?
We are catching these "typos" now, and I believe this can be useful to prevent errors produced by copy and pasting, when quotation marks might be added accidentally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If quotation marks are added accidentally, they should added at both sides and be different from quotations inside. I don't think that we should accept arbitrary garbage.
The current code misbehave not only with r'
, but with '
and """
. And your current patch doesn't fixes the latter two cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I believe you are right. I'll update the PR to address this :)
@@ -0,0 +1,2 @@ | |||
Fix trailing quotation marks getting deleted when looking up byte/string | |||
literals on pydoc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add "Patch by yourname."
Lib/pydoc.py
Outdated
|
||
# Make sure significant trailing quoting marks of literals don't | ||
# get deleted while cleaning input | ||
if request.lower() not in self._strprefixes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about '
and """
?
You are right. I'll update to reflect both of your last two comments.
…On Sat, May 5, 2018, 10:04 Serhiy Storchaka ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In Misc/NEWS.d/next/Library/2018-05-05-09-53-05.bpo-33422.4FtQ0q.rst
<#6701 (comment)>:
> @@ -0,0 +1,2 @@
+Fix trailing quotation marks getting deleted when looking up byte/string
+literals on pydoc
Please add "Patch by *yourname*."
------------------------------
In Lib/pydoc.py
<#6701 (comment)>:
> @@ -1910,7 +1911,12 @@ 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 request.lower() not in self._strprefixes:
What about ' and """?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#6701 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Ag_DMWvPixzMJ3mSQtiESEGV0AWwEoklks5tvaNVgaJpZM4Tx734>
.
|
Thanks @andresdelfino for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6, 3.7. |
…tring literals on pydoc. (pythonGH-6701) Also update the list of string prefixes. (cherry picked from commit b2043bb) Co-authored-by: Andrés Delfino <adelfino@gmail.com>
GH-6709 is a backport of this pull request to the 3.7 branch. |
…trin 8000 g literals on pydoc. (pythonGH-6701) Also update the list of string prefixes. (cherry picked from commit b2043bb) Co-authored-by: Andrés Delfino <adelfino@gmail.com>
GH-6710 is a backport of this pull request to the 3.6 branch. |
Sorry, @andresdelfino and @serhiy-storchaka, I could not cleanly backport this to |
…byte/string literals on pydoc. (pythonGH-6701) Also update the list of string prefixes.. (cherry picked from commit b2043bb) Co-authored-by: Andrés Delfino <adelfino@gmail.com>
GH-6712 is a backport of this pull request to the 2.7 branch. |
…t while at it
https://bugs.python.org/issue33422