fastapi/fastapi
Claude 03067fc675
Add SecretBytes and NewType support for File() parameter
Support using SecretBytes type annotation with File() parameter, similar to
how bytes is supported. This enables secure handling of file content that
should not be logged or displayed.

Also add support for NewType wrappers around bytes and SecretBytes types
by unwrapping NewType in type detection functions.

- Add _unwrap_newtype() helper to handle NewType wrappers
- Update is_bytes_or_nonable_bytes_annotation() to check for SecretBytes
  (both pydantic.types.SecretBytes and pydantic.v1.types.SecretBytes)
- Update is_bytes_field() in v1.py for Pydantic v1 compatibility
- Add comprehensive tests for SecretBytes and NewType with File()

Supports: SecretBytes, SecretBytes | None, List[SecretBytes],
          NewType('X', bytes), NewType('X', SecretBytes)

Co-authored-by: Kamil Monicz <kamil@monicz.dev>
2025-12-01 17:35:14 +00:00
..
_compat Add SecretBytes and NewType support for File() parameter 2025-12-01 17:35:14 +00:00
dependencies 🐛 Cache dependencies that don't use scopes and don't have sub-dependencies with scopes (#14419) 2025-11-30 15:45:49 +01:00
middleware 🐛 Fix support for `StreamingResponse`s with dependencies with `yield` or `UploadFile`s, close after the response is done (#14099) 2025-09-29 05:29:38 +02:00
openapi Migrate internal reference documentation from `typing_extensions.Doc` to `annotated_doc.Doc` (#14222) 2025-10-23 22:31:35 +02:00
security 🐛 Use `401` status code in security classes when credentials are missing (#13786) 2025-11-24 20:03:06 +01:00
__init__.py 🔖 Release version 0.123.0 2025-11-30 15:47:35 +01:00
__main__.py ♻️ Add support for `pip install "fastapi[standard]"` with standard dependencies and `python -m fastapi` (#11935) 2024-08-02 01:03:05 -05:00
applications.py Migrate internal reference documentation from `typing_extensions.Doc` to `annotated_doc.Doc` (#14222) 2025-10-23 22:31:35 +02:00
background.py Migrate internal reference documentation from `typing_extensions.Doc` to `annotated_doc.Doc` (#14222) 2025-10-23 22:31:35 +02:00
cli.py ♻️ Add support for `pip install "fastapi[standard]"` with standard dependencies and `python -m fastapi` (#11935) 2024-08-02 01:03:05 -05:00
concurrency.py 🐛 Preserve traceback when exception is raised in sync dependency with `yield` (#5823) 2024-12-03 23:37:12 +01:00
datastructures.py Migrate internal reference documentation from `typing_extensions.Doc` to `annotated_doc.Doc` (#14222) 2025-10-23 22:31:35 +02:00
encoders.py Migrate internal reference documentation from `typing_extensions.Doc` to `annotated_doc.Doc` (#14222) 2025-10-23 22:31:35 +02:00
exception_handlers.py ⬆️ Upgrade Starlette supported version range to >=0.40.0,<0.49.0 (#14077) 2025-09-16 19:21:48 +02:00
exceptions.py Add support for dependencies with scopes, support `scope="request"` for dependencies with `yield` that exit before the response is sent (#14262) 2025-11-03 11:12:49 +01:00
logger.py 🔊 Refactor logging (#781) 2019-12-09 20:02:44 +01:00
param_functions.py Add support for dependencies with scopes, support `scope="request"` for dependencies with `yield` that exit before the response is sent (#14262) 2025-11-03 11:12:49 +01:00
params.py ♻️ Make the result of `Depends()` and `Security()` hashable, as a workaround for other tools interacting with these internal parts (#14372) 2025-11-19 17:50:18 +01:00
py.typed add py.typed to ship typing information (#209) 2019-05-11 13:43:47 +04:00
requests.py ⬆ Require Pydantic > 1.0 (#1862) 2020-08-09 22:17:08 +02:00
responses.py Add reference (code API) docs with PEP 727, add subclass with custom docstrings for `BackgroundTasks`, refactor docs structure (#10392) 2023-10-18 16:36:40 +04:00
routing.py Add support for dependencies with scopes, support `scope="request"` for dependencies with `yield` that exit before the response is sent (#14262) 2025-11-03 11:12:49 +01:00
staticfiles.py Improve type annotations, add support for mypy --strict, internally and for external packages (#2547) 2020-12-20 19:50:00 +01:00
temp_pydantic_v1_params.py 🐛 Fix internal Pydantic v1 compatibility (warnings) for Python 3.14 and Pydantic 2.12.1 (#14186) 2025-10-20 13:26:49 +02:00
templating.py Improve type annotations, add support for mypy --strict, internally and for external packages (#2547) 2020-12-20 19:50:00 +01:00
testclient.py Improve type annotations, add support for mypy --strict, internally and for external packages (#2547) 2020-12-20 19:50:00 +01:00
types.py Add support for dependencies with scopes, support `scope="request"` for dependencies with `yield` that exit before the response is sent (#14262) 2025-11-03 11:12:49 +01:00
utils.py 🐛 Fix internal Pydantic v1 compatibility (warnings) for Python 3.14 and Pydantic 2.12.1 (#14186) 2025-10-20 13:26:49 +02:00
websockets.py Export `WebSocketState` in `fastapi.websockets` (#4376) 2022-09-04 17:12:10 +02:00