Skip to content

Commit 26f3335

Browse files
authored
✨ Feature: support partial funcs in pagination (#206)
1 parent 731e790 commit 26f3335

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

githubkit/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from enum import Enum
2+
from functools import partial
23
import inspect
34
from typing import Any, Generic, Literal, Optional, TypeVar, final
45

@@ -61,7 +62,18 @@ def exclude_unset(data: Any) -> Any:
6162
return data
6263

6364

65+
def _unwrap_partial(func: T) -> T:
66+
while isinstance(func, partial):
67+
func = func.func
68+
return func
69+
70+
6471
def is_async(obj: Any) -> bool:
72+
"""Check if an object is a async callable (coroutine function)."""
73+
74+
# unwrap partials first
75+
obj = _unwrap_partial(obj)
76+
6577
if inspect.isroutine(obj):
6678
return inspect.iscoroutinefunction(obj)
6779
if inspect.isclass(obj):

tests/test_rest/test_call.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from functools import partial
2+
13
import pytest
24

35
from githubkit import GitHub
@@ -60,10 +62,28 @@ def test_paginate(g: GitHub):
6062
...
6163

6264

65+
def test_paginate_with_partial(g: GitHub):
66+
paginator = g.rest.paginate(
67+
partial(g.rest.issues.list_for_repo, OWNER, REPO), per_page=50
68+
)
69+
for _ in paginator:
70+
...
71+
72+
6373
@pytest.mark.anyio
6474
async def test_async_paginate(g: GitHub):
6575
paginator = g.rest.paginate(
6676
g.rest.issues.async_list_for_repo, owner=OWNER, repo=REPO, per_page=50
6777
)
6878
async for _ in paginator:
6979
...
80+
81+
82+
@pytest.mark.anyio
83+
async def test_async_paginate_with_partial(g: GitHub):
84+
paginator = g.rest.paginate(
85+
partial(g.rest.issues.async_list_for_repo, OWNER, REPO),
86+
per_page=50,
87+
)
88+
async for _ in paginator:
89+
...

0 commit comments

Comments
 (0)