Browse Source

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)
pull/15493/head
Niki 4 weeks ago
parent
commit
12f149a3c2
  1. 2
      fastapi/_compat/v2.py
  2. 4
      scripts/add_latest_release_date.py

2
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]]]:

4
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)

Loading…
Cancel
Save