From 5a38a03bf84a4e738d1e0c38a56def60e38aa1f4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 13 Nov 2025 10:56:19 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20format?= =?UTF-8?q?=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/datastructures.py | 31 +++++++++++++++---------------- tests/test_datastructures.py | 5 +++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/fastapi/datastructures.py b/fastapi/datastructures.py index b6ff24044..b8592b5f8 100644 --- a/fastapi/datastructures.py +++ b/fastapi/datastructures.py @@ -143,23 +143,22 @@ class UploadFile(StarletteUploadFile): str, Doc("The text encoding to use when decoding bytes. Defaults to 'utf-8'."), ] = "utf-8", - ) -> str: - + ) -> str: """ - Read the entire file as a text string. - This is a convenience wrapper around `await self.read()` - that decodes the bytes using the given encoding. - ## Example - ```python - @app.post("/upload-text/") - async def upload_text(file: UploadFile): - text = await file.read_text() - return {"length": len(text)} - ``` - Args: - encoding: The text encoding to use (default: 'utf-8'). - Returns: - The decoded file content as a string. + Read the entire file as a text string. + This is a convenience wrapper around `await self.read()` + that decodes the bytes using the given encoding. + ## Example + ```python + @app.post("/upload-text/") + async def upload_text(file: UploadFile): + text = await file.read_text() + return {"length": len(text)} + ``` + Args: + encoding: The text encoding to use (default: 'utf-8'). + Returns: + The decoded file content as a string. """ data = await self.read() return data.decode(encoding) diff --git a/tests/test_datastructures.py b/tests/test_datastructures.py index f49fb431f..df965fd55 100644 --- a/tests/test_datastructures.py +++ b/tests/test_datastructures.py @@ -74,7 +74,6 @@ async def test_upload_file(): @pytest.mark.asyncio async def test_uploadfile_read_text(tmp_path): - file_path = tmp_path / "sample.txt" file_path.write_text("Hello FastAPI!") @@ -82,4 +81,6 @@ async def test_uploadfile_read_text(tmp_path): upload = UploadFile(filename="sample.txt", file=f) content = await upload.read_text() assert content == "Hello FastAPI!" - assert upload.filename == "sample.txt" # make sure .read_text() doesn't modify filename or headers \ No newline at end of file + assert ( + upload.filename == "sample.txt" + ) # make sure .read_text() doesn't modify filename or headers