-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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-12707: deprecate info(), geturl(), getcode() methods in favor of headers, url, and status properties for HTTPResponse and addinfourl #11447
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Our records indicate we have not received your CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
I think there is no consensus on the issue about raising code level deprecation as noted in https://bugs.python.org/issue12707#msg234945 and this causes a lot of tests to fail to |
@tirkarthi Makes sense, I've removed the deprecation code/notice for now. It feels odd though having multiple methods/properties that return the same thing; ideally all the duplicates should be deprecated. For now I've added the "recommended to use [x] instead" notice in the docs. |
Co-Authored-By: epicfaace <aramaswamis@gmail.com>
Lib/test/test_urllib.py
Outdated
|
||
def test_getcode(self): | ||
self.assertIsNone(self.returned_obj.getcode()) | ||
self.assertIsNone(self.returned_obj.status) |
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 think it could be cleaner to separate these tests (recommended attributes first, then the older ones)
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.
Ok.
In other tests that use the info()
, geturl()
functions, etc., do you suggest I update them to use the recommended attributes as well too?
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.
How many changes is that?
If the functions are doc-deprecated but will never actually raise warnings, maybe it’s not worth changing tens and tens of lines.
Doc/library/urllib.request.rst
Outdated
|
||
.. attribute:: addinfourl.status | ||
|
||
Status code returned by server. Recommended to use :attr:`~addinfourl.status` instead. |
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.
- The recommendation phrase :attr:
~addinfourl.status
links back to itself while building the docs locally. Also below methodsgeturl
,info
also link toaddinfourl.status
but it's documented to return only status code. Am I missing something here? status
seems to be a newly added property. Does this need aversionadded
directive?
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.
Ha this is recursive! Was probably copied from the getstatus
docs.
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.
Oops, that was a typo. Added a versionadded
directive.
Doc/library/http.client.rst
Outdated
@@ -477,6 +485,18 @@ statement. | |||
|
|||
Is ``True`` if the stream is closed. | |||
|
|||
.. method:: HTTPResponse.geturl() | |||
|
|||
Returns the URL of the resource retrieved. Recommended to use :attr:`~HTTPResponse.url` instead. |
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 this could be condensed to:
Deprecated method equivalent to :attr:`HTTPResponse.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.
Is that okay to call it "deprecated" even when it doesn't return any DeprecationWarnings when used?
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, we name that «doc-deprecated», it’s a useful degree of deprecation.
(i.e. don’t break code that is fine, don’t annoy with warnings, just recommend the obvious way to do it in docs for people who want that)
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.
Okay, I've went ahead and called it "deprecated" in the documentation. How do you keep track of which things mentioned in the documentation are deprecated and which are doc-deprecated?
Doc/library/urllib.request.rst
Outdated
|
||
.. attribute:: addinfourl.headers | ||
|
||
Returns the meta-information of the page, such as headers, |
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 does «such as» mean? Is there something else than HTTP response headers in the headers property?
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.
Again, this was moved from the original documentation, but will reword.
Doc/library/urllib.request.rst
Outdated
.. attribute:: addinfourl.headers | ||
|
||
Returns the meta-information of the page, such as headers, | ||
in the form of an :func:`email.message_from_string` instance (see |
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.
See my previous comment: this should link to the EmailMessage class, not a factory function.
Doc/library/urllib.request.rst
Outdated
|
||
Returns the meta-information of the page, such as headers, | ||
in the form of an :func:`email.message_from_string` instance (see | ||
`Quick Reference to HTTP Headers <http://jkorpela.fi/http.html>`_) |
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.
Why link to a specific personal website here? I think people know what HTTP headers are, or if they don’t other parts of the docs probably already link to general-purpose documentation (W3C or Wikipedia).
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.
Uh, I just moved over the previous documentation that was already there. Now that you mention it, it's probably better to remove it.
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.
Ah! In that case, keeping it is also OK. You can’t fix all the docs in one PR :)
Doc/library/urllib.request.rst
Outdated
|
||
.. attribute:: addinfourl.status | ||
|
||
Status code returned by server. Recommended to use :attr:`~addinfourl.status` instead. |
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.
Status code returned by server. Recommended to use :attr:`~addinfourl.status` instead. | |
Same as *code*. |
Doc/library/urllib.request.rst
Outdated
|
||
.. method:: addinfourl.geturl() | ||
|
||
Returns the URL of the resource retrieved. Recommended to use :attr:`~addinfourl.status` instead. |
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 do you think of:
Returns the URL of the resource retrieved. Recommended to use :attr:`~addinfourl.status` instead. | |
Deprecated method equivalent to :attr:`~addinfourl.url`. |
Doc/library/urllib.request.rst
Outdated
|
||
.. method:: addinfourl.info() | ||
|
||
Returns the response headers. Recommended to use :attr:`~addinfourl.status` instead. |
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.
headers not status!
Doc/library/urllib.request.rst
Outdated
|
||
Returns the status. Recommended to use :attr:`~addinfourl.status` instead. |
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.
Should status or code be the obvious recommended attribute?
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.
Since originally both HTTPResponse
and getaddrurl
had the same three functions, info()
, geturl()
, and getcode()
, and now we're replacing them with attributes instead. Both classes have .headers
and .url
so we're good with those two. However, there is no uniform attribute for the status code; we have HTTPResponse.status
and addinfourl.code
.
Since it seems like HTTPResponse.status
is already documented, I thought it would be better just to rename addinfourl.code
to addinfourl.status
for consistency's sake.
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.
Agreed that following HTTPResponse is best.
Suggested doc for status property: Returns the status code.
Doc for code: Same as status
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.
Sorry I am confused: does addinfourl.code already exist in a released version? If yes, I think we should keep it, recommend status
, and not add code
to HTTPResponse. If no, let’s keep only getcode (old) and status (recommended, same name as other class). Sounds good?
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.
Oops, I made a typo. What I meant to say is that: HTTPResponse.status
and addinfourl.code
already both exist in a released version.
So my solution was to add a property called addinfourl.status
which would be recommended to use over addinfourl.code
.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
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.
Thank you for your contribution but could you update your PR with my remarks.
Misc/NEWS.d/next/Documentation/2019-08-27-01-14-59.bpo-12707.Yj3_7_.rst
Outdated
Show resolved
Hide resolved
Doc/library/http.client.rst
Outdated
@@ -477,6 +485,18 @@ statement. | |||
|
|||
Is ``True`` if the stream is closed. | |||
|
|||
.. method:: HTTPResponse.geturl() | |||
|
|||
Deprecated method equivalent to :attr:`HTTPResponse.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.
Could you use
.. deprecated:: 3.9
The method :method:`HTTPResponse.geturl` is deprecated in favor of :attr:`HTTPResponse.url`
Check for the other attributes and the right syntax.
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 disagree! Why generate a link to the section that we’re already in?
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.
Ok, I've done something in between by starting the sentence just with "Deprecated in favor" while still keeping the deprecated::
markup.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be put in the comfy chair! |
I have made the requested changes; please review again |
Thanks for making the requested changes! @merwok, @matrixise: please review the changes made to this pull request. |
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.
Thank you for your contribution
@epicfaace I have fixed the |
I have seen an error with the deprecated directive and I can't compile the doc on my laptop
Thank you so much for your contribution, I closed the issue and have merged this PR. |
This PR documented functions returning a status code as Please could someone review PR #101296 to fix it? |
https://bugs.python.org/issue12707