-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-35075: Fix broken url in the pprint documentation #10201
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
Conversation
This doesn't work on my local Python build with a |
@lysnikolaou Yup, the Thanks for the catch! |
Doc/library/pprint.rst
Outdated
@@ -217,9 +217,10 @@ let's fetch information about a project from `PyPI <https://pypi.org>`_:: | |||
>>> import json | |||
>>> import pprint | |||
>>> from urllib.request import urlopen | |||
>>> with urlopen('http://pypi.org/project/Twisted/json') as url: | |||
>>> with urlopen('https://pypi.org/pypi/Twisted/json') as url: |
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.
Output of this URL is changed, and it's too large for example. (Output is in below).
I think we should find better json example.
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.
Maybe we can add a new JSON file in https://github.com/python/pythontestdotnet which is used for testing purposes? Is it necessary to make a request to pypi since we can define a minimal custom dict based on the current example to show the output and usage of other parameters like depth
and width
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.
By using PyPI, it looks more "pragmatic" rather than "artificial" example.
I found nice example: https://pypi.org/pypi/sampleproject/json
This project is maintained by PyPA.
Doc/library/pprint.rst
Outdated
... http_info = url.info() | ||
... raw_data = url.read().decode(http_info.get_content_charset()) | ||
... charset = http_info.get_content_charset(failobj="utf-8") | ||
... raw_data = url.read().decode(charset) |
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.
This is example of pprint
. So this part should be simple as possible:
with urlopen('https://pypi.org/pypi/Twisted/json') as resp:
project_info = json.load(resp)
Note that json.load
and json.loads
now support loading bytes encoded with UTF-8.
So no need to manual decode.
When you're done making the requested changes, leave the comment: |
I have made the requested changes; please review again |
Thanks for making the requested changes! @methane: please review the changes made to this pull request. |
Co-Authored-By: pablogsal <[email protected]>
Doc/library/pprint.rst
Outdated
... raw_data = url.read().decode(http_info.get_content_charset()) | ||
>>> project_info = json.loads(raw_data) | ||
>>> with urlopen('https://pypi.org/pypi/sampleproject/json') as resp: | ||
... project_info = json.load(resp) |
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.
... project_info = json.load(resp) | |
... project_info = json.load(resp) |
Hm, output seems long yet. Please try only 'info' part:
And |
Co-Authored-By: pablogsal <[email protected]>
Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
https://bugs.python.org/issue35075 (cherry picked from commit bf46a09) Co-authored-by: Pablo Galindo <[email protected]>
GH-10282 is a backport of this pull request to the 3.7 branch. |
https://bugs.python.org/issue35075 (cherry picked from commit bf46a09) Co-authored-by: Pablo Galindo <[email protected]>
GH-10283 is a backport of this pull request to the 3.6 branch. |
https://bugs.python.org/issue35075 (cherry picked from commit bf46a09) Co-authored-by: Pablo Galindo <[email protected]>
https://bugs.python.org/issue35075 (cherry picked from commit bf46a09) Co-authored-by: Pablo Galindo <[email protected]>
https://bugs.python.org/issue35075