Skip to content

Commit ec0a63c

Browse files
authored
Add set_params function (#1029)
1 parent 6b00145 commit ec0a63c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

fastapi_pagination/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"resolve_params",
66
"response",
77
"set_page",
8+
"set_params",
89
"Page",
910
"Params",
1011
"LimitOffsetPage",
@@ -21,6 +22,7 @@
2122
resolve_params,
2223
response,
2324
set_page,
25+
set_params,
2426
)
2527
from .default import Page, Params
2628
from .limit_offset import LimitOffsetPage, LimitOffsetParams

fastapi_pagination/api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"response",
77
"request",
88
"set_page",
9+
"set_params",
910
"set_items_transformer",
1011
"apply_items_transformer",
1112
"pagination_ctx",
@@ -207,6 +208,10 @@ def _reset_ctx() -> Iterator[None]:
207208
return _reset_ctx()
208209

209210

211+
def set_params(params: AbstractParams) -> ContextManager[None]:
212+
return _ctx_var_with_reset(_params_val, params)
213+
214+
210215
def set_page(page: Type[AbstractPage[Any]]) -> ContextManager[None]:
211216
return _ctx_var_with_reset(_page_val, page)
212217

@@ -270,7 +275,7 @@ def _create_params_dependency(
270275
) -> Callable[[TAbstractParams], AsyncIterator[TAbstractParams]]:
271276
async def _pagination_params(*args: Any, **kwargs: Any) -> AsyncIterator[TAbstractParams]:
272277
val = params(*args, **kwargs)
273-
with _ctx_var_with_reset(_params_val, cast(AbstractParams, val)):
278+
with set_params(val):
274279
yield val
275280

276281
sign = inspect.signature(params)

0 commit comments

Comments
 (0)