Browse Source

🎨 [pre-commit.ci] Auto format from pre-commit.com hooks

pull/12135/head
pre-commit-ci[bot] 8 months ago
parent
commit
69d3529a4a
  1. 12
      fastapi/dependencies/utils.py
  2. 2
      tests/test_none_passed_when_null_received.py

12
fastapi/dependencies/utils.py

@ -670,18 +670,22 @@ async def solve_dependencies(
dependency_cache=dependency_cache, dependency_cache=dependency_cache,
) )
if PYDANTIC_V2: if PYDANTIC_V2:
if sys.hexversion >= 0x30a00000: if sys.hexversion >= 0x30A00000:
def _allows_none(field: ModelField) -> bool: def _allows_none(field: ModelField) -> bool:
origin = get_origin(field.type_) origin = get_origin(field.type_)
return (origin is Union or origin is types.UnionType) and type(None) in get_args( return (origin is Union or origin is types.UnionType) and type(
field.type_ None
) ) in get_args(field.type_)
else: else:
def _allows_none(field: ModelField) -> bool: def _allows_none(field: ModelField) -> bool:
origin = get_origin(field.type_) origin = get_origin(field.type_)
return origin is Union and type(None) in get_args(field.type_) return origin is Union and type(None) in get_args(field.type_)
else: else:
def _allows_none(field: ModelField) -> bool: def _allows_none(field: ModelField) -> bool:
return field.allow_none return field.allow_none

2
tests/test_none_passed_when_null_received.py

@ -10,7 +10,7 @@ DEFAULT = 1234567890
endpoints = [] endpoints = []
if sys.hexversion >= 0x30a0000: if sys.hexversion >= 0x30A0000:
from typing import Annotated from typing import Annotated
@app.post("/api1") @app.post("/api1")

Loading…
Cancel
Save