Skip to content

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

Open
Alexandr153 wants to merge 8 commits into
python:mainfrom
Alexandr153:fix-issue-123503
Open

gh-123503: Replace usages of addinfourl and HTTPResponse deprecated attributes with stable ones#132670
Alexandr153 wants to merge 8 commits into
python:mainfrom
Alexandr153:fix-issue-123503

Conversation

@Alexandr153

Copy link
Copy Markdown
Contributor

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

@picnixz

picnixz commented Apr 18, 2025

Copy link
Copy Markdown
Member

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

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

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

Comment thread Misc/NEWS.d/next/Library/2025-04-18-04-47-39.gh-issue-123503.mfg0wD.rst Outdated
@python-cla-bot

python-cla-bot Bot commented Apr 18, 2025

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

…fg0wD.rst

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. 👍

Comment thread Misc/NEWS.d/next/Library/2025-04-18-04-47-39.gh-issue-123503.mfg0wD.rst Outdated
…fg0wD.rst

Co-authored-by: Martin Panter <vadmium@users.noreply.github.com>
@vadmium

vadmium commented Apr 19, 2025

Copy link
Copy Markdown
Member

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

picnixz commented Apr 19, 2025

Copy link
Copy Markdown
Member

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?

@vadmium

vadmium commented Apr 22, 2025

Copy link
Copy Markdown
Member

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 someone using 3.13 today cannot change their deprecated code attribute and info method due to the bug. (They could add the recommended replacements, but they must keep the old ones.)

how about adding a true DeprecationWarning, without any removal plans, and implement a fallback logic if needs arise?

If the fix claims backwards compatibility, I suspect we should add that fallback logic. On the other hand, it would be simpler to just document that a custom class would need porting to the new response attributes in 3.14, and remove the claim that backwards compatibility is retained.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 23, 2026
@serhiy-storchaka

Copy link
Copy Markdown
Member

@vadmium I have added a fallback, so both spellings are accepted.

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

Labels

awaiting merge stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants