From 12f149a3c29d2da615720190939fdfc63fa53dc5 Mon Sep 17 00:00:00 2001 From: Niki Date: Sat, 9 May 2026 00:50:32 +0800 Subject: [PATCH] fix: replace mutable default arg with None and add encoding='utf-8' to open() calls - fastapi/_compat/v2.py: Replace mutable default argument with in ModelField.validate() to avoid shared state across calls (B006/W0102) - scripts/add_latest_release_date.py: Add encoding='utf-8' to both open() calls to ensure consistent file reading/writing across platforms (W1514) --- fastapi/_compat/v2.py | 2 +- scripts/add_latest_release_date.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fastapi/_compat/v2.py b/fastapi/_compat/v2.py index 3b64fba76c..05a311dbb0 100644 --- a/fastapi/_compat/v2.py +++ b/fastapi/_compat/v2.py @@ -173,7 +173,7 @@ class ModelField: def validate( self, value: Any, - values: dict[str, Any] = {}, # noqa: B006 + values: dict[str, Any] | None = None, *, loc: tuple[int | str, ...] = (), ) -> tuple[Any, list[dict[str, Any]]]: diff --git a/scripts/add_latest_release_date.py b/scripts/add_latest_release_date.py index f20b727e7a..c08446935c 100644 --- a/scripts/add_latest_release_date.py +++ b/scripts/add_latest_release_date.py @@ -9,7 +9,7 @@ RELEASE_HEADER_PATTERN = re.compile(r"^## (\d+\.\d+\.\d+)\s*(\(.*\))?\s*$") def main() -> None: - with open(RELEASE_NOTES_FILE) as f: + with open(RELEASE_NOTES_FILE, encoding="utf-8") as f: lines = f.readlines() for i, line in enumerate(lines): @@ -28,7 +28,7 @@ def main() -> None: lines[i] = f"## {version} ({today})\n" print(f"Added date: {version} ({today})") - with open(RELEASE_NOTES_FILE, "w") as f: + with open(RELEASE_NOTES_FILE, "w", encoding="utf-8") as f: f.writelines(lines) sys.exit(0)