Skip to content

Commit 7e46f2b

Browse files
authored
Remove deprecated API (#1415)
1 parent 7d80a1c commit 7e46f2b

15 files changed

+49
-618
lines changed

fastapi_pagination/api.py

Lines changed: 5 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
]
1515

1616
import inspect
17-
import warnings
1817
from collections.abc import AsyncIterator, Iterator, Sequence
1918
from contextlib import AbstractContextManager, ExitStack, asynccontextmanager, contextmanager, suppress
2019
from contextvars import ContextVar
@@ -37,7 +36,6 @@
3736
from fastapi.routing import APIRoute, APIRouter
3837
from pydantic import BaseModel
3938
from starlette.routing import request_response
40-
from typing_extensions import deprecated
4139

4240
from .bases import AbstractPage, AbstractParams
4341
from .default import Page
@@ -81,97 +79,23 @@ def pagination_items() -> Sequence[Any]:
8179
raise RuntimeError("pagination_items must be called inside create_page") from None
8280

8381

84-
_DEPRECATED_PARAM_MSG = """
85-
'{param}' is no longer can be passed as a positional argument, use keyword argument instead.
86-
Positional arguments are deprecated and will be removed in the next major release (0.13.0).
87-
"""
88-
89-
_SENTINEL: Any = object()
90-
91-
92-
@overload
9382
def create_page(
9483
items: Sequence[T],
9584
/,
96-
**kwargs: Any,
97-
) -> AbstractPage[T]:
98-
pass
99-
100-
101-
@overload
102-
@deprecated(
103-
"'total' and 'params' are deprecated parameters, use keyword arguments instead. "
104-
"These parameters are deprecated and will be removed in the next major release (0.13.0).",
105-
)
106-
def create_page(
107-
items: Sequence[T],
108-
total: Optional[int] = _SENTINEL,
109-
params: Optional[AbstractParams] = _SENTINEL,
110-
/,
111-
**kwargs: Any,
112-
) -> AbstractPage[T]:
113-
pass
114-
115-
116-
def create_page(
117-
items: Sequence[T],
118-
total: Optional[int] = _SENTINEL,
119-
params: Optional[AbstractParams] = _SENTINEL,
120-
/,
85+
total: Optional[int] = None,
86+
params: Optional[AbstractParams] = None,
12187
**kwargs: Any,
12288
) -> AbstractPage[T]:
12389
"""
12490
Creates an instance of AbstractPage with provided items and optional parameters.
12591
126-
This function uses positional-only arguments for `items`, `total`, and `params` to enforce explicit naming
127-
of these parameters when calling the function.
128-
The use of positional-only arguments also prevents the caller from providing these arguments more than once.
129-
130-
The `total` and `params` parameters are deprecated and may be removed in future versions.
131-
Their use will emit a DeprecationWarning.
132-
133-
Args:
134-
items (Sequence[T]): A sequence of items to be included in the page.
135-
total (Optional[int], deprecated): The total number of items. If not provided, defaults to _SENTINEL.
136-
If 'total' is specified in kwargs, it will raise a TypeError.
137-
params (Optional[AbstractParams], deprecated): The parameters for the page.
138-
If not provided, defaults to _SENTINEL.
139-
If 'params' is specified in kwargs, it will raise a TypeError.
140-
141-
Keyword Args:
142-
**kwargs (Any): Additional parameters. 'total' and 'params' are not allowed in kwargs.
143-
14492
Returns:
14593
AbstractPage[T]: An instance of AbstractPage containing the provided items and additional parameters.
146-
147-
Raises:
148-
TypeError: If 'total' or 'params' are specified more than once (either as named arguments or in kwargs).
149-
DeprecationWarning: If 'total' or 'params' are provided (as these are deprecated parameters).
15094
"""
151-
152-
if params is not _SENTINEL:
153-
if "params" in kwargs:
154-
raise TypeError("create_page() got multiple values for argument 'params'")
155-
156-
kwargs["params"] = params
157-
158-
warnings.warn(
159-
_DEPRECATED_PARAM_MSG.format(param="params"),
160-
DeprecationWarning,
161-
stacklevel=2,
162-
)
163-
164-
if total is not _SENTINEL:
165-
if "total" in kwargs:
166-
raise TypeError("create_page() got multiple values for argument 'total'")
167-
95+
if total is not None:
16896
kwargs["total"] = total
169-
170-
warnings.warn(
171-
_DEPRECATED_PARAM_MSG.format(param="total"),
172-
DeprecationWarning,
173-
stacklevel=2,
174-
)
97+
if params is not None:
98+
kwargs["params"] = params
17599

176100
with _ctx_var_with_reset(_items_val, items):
177101
return _page_val.get().create(items, **kwargs)

fastapi_pagination/async_paginator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def paginate(
3737

3838
return create_page(
3939
t_items,
40-
total=total,
40+
total=total, # type: ignore[arg-type]
4141
params=params,
4242
**(additional_data or {}),
4343
)

fastapi_pagination/bases.py

Lines changed: 6 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
"is_limit_offset",
1212
]
1313

14-
import inspect
15-
import warnings
1614
from abc import ABC, abstractmethod
1715
from contextlib import suppress
1816
from dataclasses import dataclass
@@ -23,10 +21,9 @@
2321
Generic,
2422
Optional,
2523
TypeVar,
26-
cast,
2724
)
2825

29-
from .utils import IS_PYDANTIC_V2, get_caller
26+
from .utils import IS_PYDANTIC_V2
3027

3128
if IS_PYDANTIC_V2:
3229
from pydantic import BaseModel as GenericModel
@@ -44,7 +41,7 @@ class PydanticUndefinedAnnotation(Exception): # type: ignore[no-redef]
4441

4542
from collections.abc import Sequence
4643

47-
from typing_extensions import Self, TypeGuard, deprecated
44+
from typing_extensions import Self, TypeGuard
4845

4946
from .types import Cursor, GreaterEqualZero, ParamsType
5047

@@ -109,36 +106,6 @@ def to_raw_params(self) -> BaseRawParams:
109106
pass
110107

111108

112-
def _new_page_signature(items: Sequence[T], params: AbstractParams, **kwargs: Any) -> type:
113-
return int
114-
115-
116-
_NEW_SIGNATURE = inspect.signature(_new_page_signature)
117-
118-
119-
def _check_for_old_sign(func: Any) -> bool:
120-
sign = inspect.signature(func)
121-
122-
try:
123-
sign.bind([], None)
124-
except TypeError:
125-
return True
126-
127-
has_kwargs = False
128-
pos_params = []
129-
for param in sign.parameters.values():
130-
if param.kind == param.POSITIONAL_OR_KEYWORD:
131-
pos_params.append(param.name)
132-
elif param.kind == param.VAR_KEYWORD:
133-
has_kwargs = True
134-
elif param.kind == param.KEYWORD_ONLY and param.default is inspect.Parameter.empty:
135-
return True
136-
elif param.kind in {param.POSITIONAL_ONLY, param.VAR_POSITIONAL}:
137-
return True
138-
139-
return not (pos_params == ["items", "params"] and has_kwargs)
140-
141-
142109
class AbstractPage(GenericModel, Generic[T], ABC):
143110
__params_type__: ClassVar[type[AbstractParams]]
144111

@@ -166,94 +133,15 @@ def __pydantic_init_subclass__(cls, **kwargs: Any) -> None:
166133
with suppress(PydanticUndefinedAnnotation):
167134
cls.model_rebuild(force=True)
168135

169-
def __init_subclass__(cls, **kwargs: Any) -> None:
170-
try:
171-
is_same = cls.create.__func__ is AbstractPage.create.__func__ # type: ignore[attr-defined]
172-
except AttributeError:
173-
is_same = False
174-
175-
if not is_same and _check_for_old_sign(cls.create):
176-
warnings.warn(
177-
"The signature of the `AbstractPage.create` method has changed. "
178-
f"Please, update it to the new one. {_NEW_SIGNATURE}"
179-
"\nSupport of old signature will be removed in the next major release (0.13.0).",
180-
DeprecationWarning,
181-
stacklevel=3,
182-
)
183-
184-
super().__init_subclass__(**kwargs)
185-
186136
@classmethod
187137
@abstractmethod
188138
def create(
189-
cls: type[C],
190-
*args: Any,
191-
**kwargs: Any,
192-
) -> C:
193-
pass
194-
195-
@classmethod
196-
def _old_customization(
197-
cls,
198-
custom_params: Optional[type[AbstractParams]] = None,
199-
/,
200-
*,
201-
cls_name: Optional[str] = None,
202-
module: Optional[str] = None,
203-
**kwargs: Any,
204-
) -> type[Self]:
205-
from .customization import CustomizedPage, PageCustomizer, UseModule, UseName, UseParams, UseParamsFields
206-
207-
args: list[PageCustomizer] = []
208-
209-
if cls_name:
210-
args.append(UseName(cls_name))
211-
if module:
212-
args.append(UseModule(module))
213-
if custom_params:
214-
args.append(UseParams(custom_params))
215-
if kwargs:
216-
args.append(UseParamsFields(**kwargs))
217-
218-
return cast(type[Self], CustomizedPage[(cls, *args)])
219-
220-
@classmethod
221-
@deprecated(
222-
"`with_custom_options` method is deprecated, please use "
223-
"`fastapi_pagination.customization.CustomizePage` instead. "
224-
"This method will be removed in the next major release (0.13.0)."
225-
)
226-
def with_custom_options(
227139
cls,
228-
*,
229-
cls_name: Optional[str] = None,
230-
module: Optional[str] = None,
140+
items: Sequence[T],
141+
params: AbstractParams,
231142
**kwargs: Any,
232-
) -> type[Self]:
233-
return cls._old_customization(
234-
cls_name=cls_name,
235-
module=module or get_caller(),
236-
**kwargs,
237-
)
238-
239-
@classmethod
240-
@deprecated(
241-
"`with_params` method is deprecated, please use "
242-
"`fastapi_pagination.customization.CustomizePage` instead. "
243-
"This method will be removed in the next major release (0.13.0)."
244-
)
245-
def with_params(
246-
cls,
247-
custom_params: type[AbstractParams],
248-
*,
249-
cls_name: Optional[str] = None,
250-
module: Optional[str] = None,
251-
) -> type[Self]:
252-
return cls._old_customization(
253-
custom_params,
254-
cls_name=cls_name,
255-
module=module or get_caller(),
256-
)
143+
) -> Self:
144+
pass
257145

258146
if IS_PYDANTIC_V2:
259147
model_config = {

fastapi_pagination/default.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
__all__ = [
4-
"OptionalParams",
54
"Page",
65
"Params",
76
]
@@ -12,7 +11,6 @@
1211

1312
from fastapi import Query
1413
from pydantic import BaseModel
15-
from typing_extensions import deprecated
1614

1715
from .bases import AbstractParams, BasePage, RawParams
1816
from .types import GreaterEqualOne, GreaterEqualZero
@@ -32,16 +30,6 @@ def to_raw_params(self) -> RawParams:
3230
)
3331

3432

35-
@deprecated(
36-
"`OptionalParams` class is deprecated, please use "
37-
"`CustomizePage[Page, UseOptionalParams()]` instead. "
38-
"This class will be removed in the next major release (0.13.0)."
39-
)
40-
class OptionalParams(Params):
41-
page: Optional[int] = Query(None, ge=1, description="Page number") # type: ignore[assignment]
42-
size: Optional[int] = Query(None, ge=1, le=100, description="Page size") # type: ignore[assignment]
43-
44-
4533
class Page(BasePage[T], Generic[T]):
4634
page: Optional[GreaterEqualOne]
4735
size: Optional[GreaterEqualOne]

fastapi_pagination/ext/async_sqlalchemy.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)