mirror of https://github.com/tiangolo/fastapi.git
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
This commit is contained in:
parent
8721352a03
commit
ab997c5821
|
|
@ -5,12 +5,14 @@ from starlette.exceptions import HTTPException as StarletteHTTPException
|
||||||
from starlette.exceptions import WebSocketException as StarletteWebSocketException
|
from starlette.exceptions import WebSocketException as StarletteWebSocketException
|
||||||
from typing_extensions import Annotated, Doc
|
from typing_extensions import Annotated, Doc
|
||||||
|
|
||||||
|
|
||||||
class EndpointContext(TypedDict, total=False):
|
class EndpointContext(TypedDict, total=False):
|
||||||
function: str
|
function: str
|
||||||
path: str
|
path: str
|
||||||
file: str
|
file: str
|
||||||
line: int
|
line: int
|
||||||
|
|
||||||
|
|
||||||
class HTTPException(StarletteHTTPException):
|
class HTTPException(StarletteHTTPException):
|
||||||
"""
|
"""
|
||||||
An HTTP exception you can raise in your own code to show errors to the client.
|
An HTTP exception you can raise in your own code to show errors to the client.
|
||||||
|
|
|
||||||
|
|
@ -243,6 +243,7 @@ def _extract_endpoint_context(func: Any) -> EndpointContext:
|
||||||
_endpoint_context_cache[func_id] = ctx
|
_endpoint_context_cache[func_id] = ctx
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
|
||||||
async def serialize_response(
|
async def serialize_response(
|
||||||
*,
|
*,
|
||||||
field: Optional[ModelField] = None,
|
field: Optional[ModelField] = None,
|
||||||
|
|
@ -354,7 +355,11 @@ def get_request_handler(
|
||||||
)
|
)
|
||||||
|
|
||||||
# Extract endpoint context for error messages
|
# Extract endpoint context for error messages
|
||||||
endpoint_ctx = _extract_endpoint_context(dependant.call) if dependant.call else EndpointContext()
|
endpoint_ctx = (
|
||||||
|
_extract_endpoint_context(dependant.call)
|
||||||
|
if dependant.call
|
||||||
|
else EndpointContext()
|
||||||
|
)
|
||||||
if dependant.path:
|
if dependant.path:
|
||||||
endpoint_ctx["path"] = f"{request.method} {dependant.path}"
|
endpoint_ctx["path"] = f"{request.method} {dependant.path}"
|
||||||
|
|
||||||
|
|
@ -480,7 +485,11 @@ def get_websocket_app(
|
||||||
embed_body_fields: bool = False,
|
embed_body_fields: bool = False,
|
||||||
) -> Callable[[WebSocket], Coroutine[Any, Any, Any]]:
|
) -> Callable[[WebSocket], Coroutine[Any, Any, Any]]:
|
||||||
async def app(websocket: WebSocket) -> None:
|
async def app(websocket: WebSocket) -> None:
|
||||||
endpoint_ctx = _extract_endpoint_context(dependant.call) if dependant.call else EndpointContext()
|
endpoint_ctx = (
|
||||||
|
_extract_endpoint_context(dependant.call)
|
||||||
|
if dependant.call
|
||||||
|
else EndpointContext()
|
||||||
|
)
|
||||||
if dependant.path:
|
if dependant.path:
|
||||||
endpoint_ctx["path"] = f"WS {dependant.path}"
|
endpoint_ctx["path"] = f"WS {dependant.path}"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue