Skip to content

gh-123503: Replace usages of addinfourl and HTTPResponse deprecated attributes with stable ones #132670

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Alexandr153
Copy link
Contributor

I replaced deprecated features with the recommended current features(updated to the latest version)

@picnixz
Copy link
Member

picnixz commented Apr 18, 2025

Please, don't re-create your PRs. Next time, just ask if there is some issue with git and I'll try helping you.

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

I would say "yes, let's do this", but I honestly want a second opinion on this change. We can always revert it later during the beta if this causes issues, though.

cc @serhiy-storchaka @vadmium

@python-cla-bot
Copy link

python-cla-bot bot commented Apr 18, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

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.

LGTM. 👍

@vadmium
Copy link
Member

vadmium commented Apr 19, 2025

I don’t understand what you mean by “while retaining backwards compatibility”. Why are you changing the test suite?

There doesn’t seem to be any consideration given to existing user code, such as the caching class in the bug report. Does this change break code that implements code but not status? Does it break code implementing info but not headers? Before 3.9, only HTTP and HTTPS responses had the status attribute, and headers was not documented while info was.

I winder if we at least need documentation saying what changes a user needs to remain compatible with the changes in Python. Maybe also fall back to the old attribute and method as well? This is the problem with deprecating two-way APIs that are implemented in both user code and Python.

@picnixz
Copy link
Member

picnixz commented Apr 19, 2025

I winder if we at least need documentation saying what changes a user needs to remain compatible with the changes in Python

Mmh, I see your point. You mean that "what if someone coming from something before 3.9 is now trying to port stuff to Python 3.14"? I'd say that anything marked as being deprecated should also be changed on their side but I guess it doesn't hurt having a paragraph in "Porting to 3.14".

Does this change break code that implements code but not status

Strictly speaking, yes. But I wouldn't consider this as being critical as the attribute has been marked as deprecated since 3.9. And any class that inherits from HTTPResponse or addinfourl would automatically have a status attribute.

Does it break code implementing info but not headers

I'd say it's the same as above.


That being said, we're already using "possible missing" attributes in, for instance, xmlrpc:

try:
    http_conn = self.send_request(host, handler, request_body, verbose)
    resp = http_conn.getresponse()
    if resp.status == 200:
        self.verbose = verbose
        return self.parse_response(resp)

OTOH, for contextlib.closing(urlopen(url, data)) as fp: and the change fp.info() to fp.headers, the docs for urlopen says (emphasis mine):

This function always returns an object which can work as a
context manager and has the properties url, headers, and status.

So we should already be on the safe side. But OTOH, the changes to other occurrences may indeed break stuff, though I wouldn't consider this as being critical, especially if it's something that's been deprecated since 3.9.

In the original report, what was actually annoying was more that users need to provide the deprecated attributes as well. So I think it's better to move forwards, at the cost of possibly breaking APIs that use deprecated attributes.

Now, if you want to be on the safe side, how about adding a true DeprecationWarning, without any removal plans, and implement a fallback logic if needs arise?

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

Successfully merging this pull request may close these issues.

4 participants