8000 bpo-33422: Consider the special case of string/byte literals, and update the lis… by andresdelfino · Pull Request #6701 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

Merged

Conversation

andresdelfino
Copy link
Contributor
@andresdelfino andresdelfino commented May 3, 2018

@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error needs backport to 3.6 labels May 5, 2018
Copy link
Member
@serhiy-storchaka serhiy-storchaka left a 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
Copy link
Member

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).

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about ' and """?

@andresdelfino
Copy link
Contributor Author
andresdelfino commented May 5, 2018 via email

@serhiy-storchaka serhiy-storchaka merged commit b2043bb into python:master May 5, 2018
@miss-islington
Copy link
Contributor

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.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 5, 2018
…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>
@bedevere-bot
Copy link

GH-6709 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 5, 2018
…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>
@bedevere-bot
Copy link

GH-6710 is a backport of this pull request to the 3.6 branch.

@miss-islington
Copy link
Contributor

Sorry, @andresdelfino and @serhiy-storchaka, I could not cleanly backport this to 2.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker b2043bbe6034b53f5ad337887f4741b74b70b00d 2.7

miss-islington added a commit that referenced this pull request May 5, 2018
…tring 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>
@andresdelfino andresdelfino deleted the fix-and-update-literals-in-help branch May 5, 2018 16:54
miss-islington added a commit that referenced this pull request May 5, 2018
…tring 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>
andresdelfino added a commit to andresdelfino/cpython that referenced this pull request May 5, 2018
…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>
@bedevere-bot
Copy link

GH-6712 is a backport of this pull request to the 2.7 branch.

serhiy-storchaka pushed a commit that referenced this pull request May 7, 2018
…byte/string literals on pydoc. (GH-6701) (GH-6712)

Also update the list of string prefixes.
(cherry picked from commit b2043bb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0