Skip to content

Commit 93dce6c

Browse files
committed
fix: generic type aliases
1 parent 1fb2f58 commit 93dce6c

3 files changed

Lines changed: 15 additions & 18 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
python-version: ["3.10", "3.12", "3.14"]
13+
python-version: ["3.10.0", "3.11", "3.12", "3.14"]
1414

1515
steps:
1616
- uses: actions/checkout@v4

src/faceit/api/pagination.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,15 @@
5050
validate_positive_int,
5151
)
5252

53-
ProcessedPages: TypeAlias = list[RawAPIItem] | ItemPage[_T]
54-
_PageType: TypeAlias = RawAPIPageResponse | ItemPage[_T]
55-
_PageList: TypeAlias = list[_PageType[_T]]
56-
_PageT = TypeVar("_PageT", bound=_PageType[Any])
53+
_PageType: TypeAlias = RawAPIPageResponse | ItemPage[Any]
54+
_PageList: TypeAlias = list[_PageType]
55+
_PageT = TypeVar("_PageT", bound=_PageType)
5756

5857

5958
if TYPE_CHECKING:
6059
_PageFactoryMap: TypeAlias = Mapping[
6160
"CollectReturnFormat",
62-
Callable[[_PageList[Any]], type[RawAPIPageResponse | ItemPage[Any]]],
61+
Callable[[_PageList], type[RawAPIPageResponse | ItemPage[Any]]],
6362
]
6463
_OptionalTimestampPaginationConfig: TypeAlias = (
6564
"TimestampPaginationConfig | Literal[False]"
@@ -157,14 +156,12 @@ def _extract_pagination_limits(
157156
):
158157
msg = f"Default for limit/offset in {method_name!r} is not a FieldInfo"
159158
raise TypeError(msg)
160-
limit_constraint = _get_le(limit_param)
161-
if limit_constraint is None:
159+
if (limit_constraint := _get_le(limit_param)) is None:
162160
msg = f"In limit metadata of {method_name!r}, no Le constraint found"
163161
raise ValueError(msg)
164-
offset_constraint = _get_le(offset_param)
165162
offset = (
166163
None
167-
if offset_constraint is None
164+
if (offset_constraint := _get_le(offset_param)) is None
168165
else validate_positive_int(offset_constraint.le)
169166
)
170167
return PaginationMaxParams(validate_positive_int(limit_constraint.le), offset)
@@ -426,7 +423,7 @@ def _validate_unix_config(
426423

427424
@staticmethod
428425
def _extract_unix_timestamp(
429-
cfg: TimestampPaginationConfig, page: _PageType[Any] | None, /
426+
cfg: TimestampPaginationConfig, page: _PageType | None, /
430427
) -> int | None:
431428
if not page:
432429
return None
@@ -468,10 +465,10 @@ def _validate_unix_pagination_parameter(
468465
@classmethod
469466
def _process_collected_pages(
470467
cls,
471-
collection: _PageList[_T],
468+
collection: list[RawAPIPageResponse | ItemPage[_T]],
472469
return_format: CollectReturnFormat,
473470
deduplicate: bool, # noqa: FBT001
474-
) -> ProcessedPages[_T]:
471+
) -> list[RawAPIItem] | ItemPage[_T]:
475472
if cls._COLLECT_RETURN_FORMATS[return_format](collection) is dict:
476473
raw = chain.from_iterable(
477474
p[RAW_RESPONSE_ITEMS_KEY] for p in collection if isinstance(p, dict)
@@ -483,7 +480,7 @@ def _process_collected_pages(
483480
@classmethod
484481
def _deduplicate_collection(
485482
cls, collection: Iterable[RawAPIItem] | ItemPage[_T], /
486-
) -> ProcessedPages[_T]:
483+
) -> list[RawAPIItem] | ItemPage[_T]:
487484
if not isinstance(collection, ItemPage):
488485
return deduplicate_unhashable(collection)
489486
return collection.with_items(deduplicate_unhashable(collection)) # pyright: ignore[reportArgumentType, reportReturnType]
@@ -579,7 +576,7 @@ def collect(
579576
self: SyncPageIterator[RawAPIPageResponse] | SyncPageIterator[ItemPage[_T]],
580577
*,
581578
deduplicate: bool = True,
582-
) -> ProcessedPages[_T]:
579+
) -> list[RawAPIItem] | ItemPage[_T]:
583580
return self.__class__.gather_from_iterator(self, deduplicate=deduplicate)
584581

585582
@classmethod
@@ -651,7 +648,7 @@ def gather_from_iterator(
651648
return_format: CollectReturnFormat = CollectReturnFormat.FIRST,
652649
*,
653650
deduplicate: bool = True,
654-
) -> ProcessedPages[_T]:
651+
) -> list[RawAPIItem] | ItemPage[_T]:
655652
return cls._process_collected_pages(list(iterator), return_format, deduplicate)
656653

657654

@@ -671,7 +668,7 @@ async def collect(
671668

672669
async def collect(
673670
self: AsyncPageIterator[RawAPIPageResponse] | AsyncPageIterator[ItemPage[_T]],
674-
) -> ProcessedPages[_T]:
671+
) -> list[RawAPIItem] | ItemPage[_T]:
675672
return await self.__class__.gather_from_iterator(self)
676673

677674
@classmethod
@@ -743,7 +740,7 @@ async def gather_from_iterator(
743740
return_format: CollectReturnFormat = CollectReturnFormat.FIRST,
744741
*,
745742
deduplicate: bool = True,
746-
) -> ProcessedPages[_T]:
743+
) -> list[RawAPIItem] | ItemPage[_T]:
747744
return cls._process_collected_pages(
748745
[page async for page in iterator], return_format, deduplicate
749746
)

0 commit comments

Comments
 (0)