Skip to content

Commit d8fec5e

Browse files
committed
Correctly handle default value for length_function param
1 parent fe4833a commit d8fec5e

File tree

3 files changed

+330
-324
lines changed

3 files changed

+330
-324
lines changed

fastapi_pagination/async_paginator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ async def apaginate(
2929
if not safe:
3030
check_installed_extensions()
3131

32-
length_function = length_function or len
32+
if length_function is None:
33+
length_function = len
3334

3435
return await run_async_flow(
3536
generic_flow(

fastapi_pagination/paginator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
def paginate(
1717
sequence: Sequence[T],
1818
params: Optional[AbstractParams] = None,
19-
length_function: Callable[[Sequence[T]], int] = len,
19+
length_function: Optional[Callable[[Sequence[T]], int]] = None,
2020
*,
2121
safe: bool = False,
2222
transformer: Optional[SyncItemsTransformer] = None,
@@ -26,6 +26,9 @@ def paginate(
2626
if not safe:
2727
check_installed_extensions()
2828

29+
if length_function is None:
30+
length_function = len
31+
2932
return run_sync_flow(
3033
generic_flow(
3134
limit_offset_flow=flow_expr(lambda r: sequence[r.as_slice()]),

0 commit comments

Comments
 (0)