Skip to content

Raise ValueError on Response.encoding being set after Response.text has been accessed - #2852

Merged
lovelydinosaur merged 3 commits into
encode:masterfrom
xzmeng:raise-error-set-encoding-after-decded
Sep 19, 2023
Merged

Raise ValueError on Response.encoding being set after Response.text has been accessed#2852
lovelydinosaur merged 3 commits into
encode:masterfrom
xzmeng:raise-error-set-encoding-after-decded

Conversation

@xzmeng

@xzmeng xzmeng commented Sep 17, 2023

Copy link
Copy Markdown

Discussed in #2041

Summary

After Response.text is accessed, if you try to change Response.encoding, nothing happens. So just raise an Exception on change to encoding after text is accessed.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
@lovelydinosaur

Copy link
Copy Markdown
Member

Okay yes, as discussed this is probably a marginal improvement in behaviour. Thanks.

Comment thread tests/models/test_responses.py Outdated
@lovelydinosaur

Copy link
Copy Markdown
Member

What's a more precise title for this PR?

@xzmeng xzmeng changed the title Raise ValueError on change encoding Sep 18, 2023
@xzmeng

xzmeng commented Sep 18, 2023

Copy link
Copy Markdown
Author

Modified. I'm not proficient in English, please change it if it's not appropriate.

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

All looking great, thanks. 😊

I think we just need to update the CHANGELOG.md, then this is good to go.

@lovelydinosaur
lovelydinosaur merged commit 59df819 into encode:master Sep 19, 2023
@lovelydinosaur lovelydinosaur mentioned this pull request Nov 2, 2023
samclearman pushed a commit to titanmsp/httpx that referenced this pull request Apr 26, 2025
…t` has been accessed (encode#2852)

* Raise ValueError on change encoding

* Always raise ValueError for simplicity

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

Labels

None yet

3 participants