Browse Source

Apply suggestions from code review

Co-authored-by: Victorien <[email protected]>
pull/14036/head
Sofie Van Landeghem 10 months ago
committed by Colin Watson
parent
commit
42ae353de0
  1. 8
      fastapi/_compat.py
  2. 4
      tests/test_multi_body_errors.py

8
fastapi/_compat.py

@ -111,10 +111,10 @@ if PYDANTIC_V2:
def __post_init__(self) -> None:
with warnings.catch_warnings():
# Pydantic >= 2.12.0a1 warns about this when building
# TypeAdapters from field information that uses aliases.
# The Pydantic team recommends ignoring this in this case:
# https://github.com/fastapi/fastapi/pull/14036#issuecomment-3316045587
# Pydantic >= 2.12.0 warns about field specific metadata that is unused
# (e.g. `TypeAdapter(Annotated[int, Field(alias='b')])`). In some cases, we
# end up building the type adapter from a model field annotation so we
# need to ignore the warning:
try:
from pydantic.warnings import ( # type: ignore[attr-defined]
UnsupportedFieldAttributeWarning,

4
tests/test_multi_body_errors.py

@ -186,9 +186,9 @@ def test_openapi_schema():
"anyOf": [
{"exclusiveMinimum": 0.0, "type": "number"},
IsOneOf(
# pydantic < 2.12.0a1
# pydantic < 2.12.0
{"type": "string"},
# pydantic >= 2.12.0a1
# pydantic >= 2.12.0
{
"type": "string",
"pattern": r"^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$",

Loading…
Cancel
Save