← mined_httpx_oracle2

httpx_2852

failed WRONG_FIX UNSUBMITTED wrong_fix_unsubmitted(None) · None tool calls · 0 s · encode/httpx

Task input

(not found in data/tasks.jsonl)

Tool calls (0)

#ToolArgumentsResult
No trace captured.

Patch

--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
 
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 
+## Unreleased
+
+### Fixed
+
+* Raise `ValueError` on `Response.encoding` being set after `Response.text` has been accessed. (#2852)
+
 ## 0.25.0 (11th Sep, 2023)
 
 ### Removed
--- a/httpx/_models.py
+++ b/httpx/_models.py
@@ -603,6 +603,16 @@ class Response:
 
     @encoding.setter
     def encoding(self, value: str) -> None:
+        """
+        Set the encoding to use for decoding the byte content into text.
+
+        If the `text` attribute has been accessed, attempting to set the
+        encoding will throw a ValueError.
+        """
+        if hasattr(self, "_text"):
+            raise ValueError(
+                "Setting encoding after `text` has been accessed is not allowed."
+            )
         self._encoding = value
 
     @property

Test output

show
ImportError while loading conftest '/private/tmp/swe_work/mined_httpx_oracle2/httpx_2852/b/workspace/tests/conftest.py'.
tests/conftest.py:20: in <module>
    import httpx
httpx/__init__.py:2: in <module>
    from ._api import delete, get, head, options, patch, post, put, request, stream
httpx/_api.py:4: in <module>
    from ._client import Client
httpx/_client.py:30: in <module>
    from ._transports.default import AsyncHTTPTransport, HTTPTransport
httpx/_transports/default.py:30: in <module>
    import httpcore
E   ModuleNotFoundError: No module named 'httpcore'