Skip to content

Commit

Permalink
🚨 use scoped typevar
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored May 21, 2024
1 parent 474ebb5 commit 9221b59
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
9 changes: 5 additions & 4 deletions githubkit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

T = TypeVar("T")
A = TypeVar("A", bound="BaseAuthStrategy")
AS = TypeVar("AS", bound="BaseAuthStrategy")


class GitHubCore(Generic[A]):
Expand All @@ -72,8 +73,8 @@ def __init__(
# other auth strategies with config
@overload
def __init__(
self: "GitHubCore[A]",
auth: A,
self: "GitHubCore[AS]",
auth: AS,
*,
config: Config,
): ...
Expand Down Expand Up @@ -113,8 +114,8 @@ def __init__(
# other auth strategies without config
@overload
def __init__(
self: "GitHubCore[A]",
auth: A,
self: "GitHubCore[AS]",
auth: AS,
*,
base_url: Optional[Union[str, httpx.URL]] = None,
accept_format: Optional[str] = None,
Expand Down
12 changes: 6 additions & 6 deletions githubkit/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


A = TypeVar("A", bound=BaseAuthStrategy)
A_o = TypeVar("A_o", bound=BaseAuthStrategy)
AS = TypeVar("AS", bound=BaseAuthStrategy)

CP = ParamSpec("CP")
CT = TypeVar("CT")
Expand Down Expand Up @@ -64,8 +64,8 @@ def __init__(
# other auth strategies with config
@overload
def __init__(
self: "GitHub[A]",
auth: A,
self: "GitHub[AS]",
auth: AS,
*,
config: Config,
): ...
Expand Down Expand Up @@ -105,8 +105,8 @@ def __init__(
# other auth strategies without config
@overload
def __init__(
self: "GitHub[A]",
auth: A,
self: "GitHub[AS]",
auth: AS,
*,
base_url: Optional[Union[str, httpx.URL]] = None,
accept_format: Optional[str] = None,
Expand All @@ -121,7 +121,7 @@ def __init__(
def __init__(self, *args, **kwargs): ...

# copy github instance with other auth
def with_auth(self, auth: A_o) -> "GitHub[A_o]":
def with_auth(self, auth: AS) -> "GitHub[AS]":
return GitHub(auth=auth, config=self.config.copy())

# rest api
Expand Down
10 changes: 5 additions & 5 deletions githubkit/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
CP = ParamSpec("CP")
CT = TypeVar("CT")
RT = TypeVar("RT")
RTI = TypeVar("RTI")
RTS = TypeVar("RTS")

R = Union[
Callable[CP, Response[RT]],
Expand All @@ -29,8 +29,8 @@
class Paginator(Generic[RT]):
@overload
def __init__(
self: "Paginator[RTI]",
request: R[CP, List[RTI]],
self: "Paginator[RTS]",
request: R[CP, List[RTS]],
page: int = 1,
per_page: int = 100,
map_func: None = None,
Expand All @@ -40,11 +40,11 @@ def __init__(

@overload
def __init__(
self: "Paginator[RTI]",
self: "Paginator[RTS]",
request: R[CP, CT],
page: int = 1,
per_page: int = 100,
map_func: Callable[[Response[CT]], List[RTI]] = ...,
map_func: Callable[[Response[CT]], List[RTS]] = ...,
*args: CP.args,
**kwargs: CP.kwargs,
): ...
Expand Down

0 comments on commit 9221b59

Please sign in to comment.