Skip to content
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

Merged
merged 31 commits into from
Sep 13, 2019

Conversation

epicfaace
Copy link
Contributor

@epicfaace epicfaace commented Jan 6, 2019

@the-knights-who-say-ni
Copy link

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
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@tirkarthi
Copy link
Member

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 DeprecationWarning as seen in the CI. I hope it's better to split the documentation changes into a separate PR without 3.8 deprecation notice in docs and code for review.

@epicfaace
Copy link
Contributor Author

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

@epicfaace epicfaace changed the title bpo-12707: deprecate info(), geturl(), getcode() methods in favor of info, url, and status properties for HTTPResponse and addinfourl bpo-12707: deprecate info(), geturl(), getcode() methods in favor of headers, url, and status properties for HTTPResponse and addinfourl Jan 7, 2019
@merwok merwok self-requested a review January 7, 2019 02:22
Doc/library/http.client.rst Outdated Show resolved Hide resolved
Doc/library/http.client.rst Outdated Show resolved Hide resolved
Doc/library/urllib.request.rst Outdated Show resolved Hide resolved
Doc/library/http.client.rst Outdated Show resolved Hide resolved
Doc/library/http.client.rst Outdated Show resolved Hide resolved

def test_getcode(self):
self.assertIsNone(self.returned_obj.getcode())
self.assertIsNone(self.returned_obj.status)
Copy link
Member

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)

Copy link
Contributor Author

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?

Copy link
Member

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.

Lib/urllib/response.py Outdated Show resolved Hide resolved

.. attribute:: addinfourl.status

Status code returned by server. Recommended to use :attr:`~addinfourl.status` instead.
Copy link
Member

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 methods geturl, info also link to addinfourl.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 a versionadded directive?

Copy link
Member

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.

Copy link
Contributor Author

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.

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

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`

Copy link
Contributor Author

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?

Copy link
Member

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)

Copy link
Contributor Author

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 Show resolved Hide resolved

.. attribute:: addinfourl.headers

Returns the meta-information of the page, such as headers,
Copy link
Member

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?

Copy link
Contributor Author

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.

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

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.


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>`_)
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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


.. attribute:: addinfourl.status

Status code returned by server. Recommended to use :attr:`~addinfourl.status` instead.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Status code returned by server. Recommended to use :attr:`~addinfourl.status` instead.
Same as *code*.


.. method:: addinfourl.geturl()

Returns the URL of the resource retrieved. Recommended to use :attr:`~addinfourl.status` instead.
Copy link
Member

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:

Suggested change
Returns the URL of the resource retrieved. Recommended to use :attr:`~addinfourl.status` instead.
Deprecated method equivalent to :attr:`~addinfourl.url`.


.. method:: addinfourl.info()

Returns the response headers. Recommended to use :attr:`~addinfourl.status` instead.
Copy link
Member

Choose a reason for hiding this comment

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

headers not status!


Returns the status. Recommended to use :attr:`~addinfourl.status` instead.
Copy link
Member

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?

Copy link
Contributor Author

@epicfaace epicfaace Jan 9, 2019

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.

Copy link
Member

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

Copy link
Member

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?

Copy link
Contributor Author

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.

Lib/urllib/response.py Show resolved Hide resolved
@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@csabella csabella reopened this May 22, 2019
@epicfaace
Copy link
Contributor Author

@csabella @merwok any updates on this?

Copy link
Member

@matrixise matrixise left a 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.

Doc/library/urllib.request.rst Outdated Show resolved Hide resolved
@@ -477,6 +485,18 @@ statement.

Is ``True`` if the stream is closed.

.. method:: HTTPResponse.geturl()

Deprecated method equivalent to :attr:`HTTPResponse.url`.
Copy link
Member

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be put in the comfy chair!

@epicfaace
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@merwok, @matrixise: please review the changes made to this pull request.

matrixise
matrixise previously approved these changes Sep 13, 2019
Copy link
Member

@matrixise matrixise left a 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

@matrixise
Copy link
Member

@epicfaace I have fixed the .. deprecated:: 3.9 in your branch, I am waiting for the green lights from Travis and I will merge it.

@matrixise matrixise dismissed their stale review September 13, 2019 11:12

I have seen an error with the deprecated directive and I can't compile the doc on my laptop

@matrixise matrixise merged commit ff2e182 into python:master Sep 13, 2019
@matrixise
Copy link
Member

Thank you so much for your contribution, I closed the issue and have merged this PR.

@hugovk
Copy link
Member

hugovk commented Feb 5, 2023

This PR documented functions returning a status code as getstatus(), when they're really getcode().

Please could someone review PR #101296 to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants