Skip to content

Feature: support partial funcs in pagination #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions githubkit/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
from functools import partial
import inspect
from typing import Any, Generic, Literal, Optional, TypeVar, final

Expand Down Expand Up @@ -61,7 +62,18 @@ def exclude_unset(data: Any) -> Any:
return data


def _unwrap_partial(func: T) -> T:
while isinstance(func, partial):
func = func.func
return func


def is_async(obj: Any) -> bool:
"""Check if an object is a async callable (coroutine function)."""

# unwrap partials first
obj = _unwrap_partial(obj)

if inspect.isroutine(obj):
return inspect.iscoroutinefunction(obj)
if inspect.isclass(obj):
Expand Down
20 changes: 20 additions & 0 deletions tests/test_rest/test_call.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from functools import partial

import pytest

from githubkit import GitHub
Expand Down Expand Up @@ -60,10 +62,28 @@ def test_paginate(g: GitHub):
...


def test_paginate_with_partial(g: GitHub):
paginator = g.rest.paginate(
partial(g.rest.issues.list_for_repo, OWNER, REPO), per_page=50
)
for _ in paginator:
...


@pytest.mark.anyio
async def test_async_paginate(g: GitHub):
paginator = g.rest.paginate(
g.rest.issues.async_list_for_repo, owner=OWNER, repo=REPO, per_page=50
)
async for _ in paginator:
...


@pytest.mark.anyio
async def test_async_paginate_with_partial(g: GitHub):
paginator = g.rest.paginate(
partial(g.rest.issues.async_list_for_repo, OWNER, REPO),
per_page=50,
)
async for _ in paginator:
...