2222import httpx
2323
2424from .response import Response
25- from .rest import RestNamespace
26- from .paginator import Paginator
2725from .exception import RequestFailed
2826from .config import Config , get_config
2927from .auth import BaseAuthStrategy , TokenAuthStrategy , UnauthAuthStrategy
30- from .graphql import GraphQLResponse , build_graphql_request , parse_graphql_response
3128from .typing import (
3229 URLTypes ,
3330 CookieTypes ,
3936
4037T = TypeVar ("T" )
4138A = TypeVar ("A" , bound = "BaseAuthStrategy" )
42- A_o = TypeVar ("A_o" , bound = "BaseAuthStrategy" )
4339
44- CP = ParamSpec ("CP" )
45- CT = TypeVar ("CT" )
46- RT = TypeVar ("RT" )
4740
48- R = Union [
49- Callable [CP , Response [List [RT ]]],
50- Callable [CP , Awaitable [Response [List [RT ]]]],
51- ]
52-
53-
54- class GitHub (Generic [A ]):
41+ class GitHubCore (Generic [A ]):
5542 # none auth with config
5643 @overload
5744 def __init__ (
58- self : "GitHub [UnauthAuthStrategy]" ,
45+ self : "GitHubCore [UnauthAuthStrategy]" ,
5946 auth : None = None ,
6047 * ,
6148 config : Config ,
@@ -65,7 +52,7 @@ def __init__(
6552 # token auth with config
6653 @overload
6754 def __init__ (
68- self : "GitHub [TokenAuthStrategy]" ,
55+ self : "GitHubCore [TokenAuthStrategy]" ,
6956 auth : str ,
7057 * ,
7158 config : Config ,
@@ -75,7 +62,7 @@ def __init__(
7562 # other auth strategies with config
7663 @overload
7764 def __init__ (
78- self : "GitHub [A]" ,
65+ self : "GitHubCore [A]" ,
7966 auth : A ,
8067 * ,
8168 config : Config ,
@@ -85,7 +72,7 @@ def __init__(
8572 # none auth without config
8673 @overload
8774 def __init__ (
88- self : "GitHub [UnauthAuthStrategy]" ,
75+ self : "GitHubCore [UnauthAuthStrategy]" ,
8976 auth : None = None ,
9077 * ,
9178 base_url : Optional [Union [str , httpx .URL ]] = None ,
@@ -100,7 +87,7 @@ def __init__(
10087 # token auth without config
10188 @overload
10289 def __init__ (
103- self : "GitHub [TokenAuthStrategy]" ,
90+ self : "GitHubCore [TokenAuthStrategy]" ,
10491 auth : str ,
10592 * ,
10693 base_url : Optional [Union [str , httpx .URL ]] = None ,
@@ -115,7 +102,7 @@ def __init__(
115102 # other auth strategies without config
116103 @overload
117104 def __init__ (
118- self : "GitHub [A]" ,
105+ self : "GitHubCore [A]" ,
119106 auth : A ,
120107 * ,
121108 base_url : Optional [Union [str , httpx .URL ]] = None ,
@@ -357,71 +344,3 @@ async def arequest(
357344 cookies = cookies ,
358345 )
359346 return self ._check (raw_resp , response_model , error_models )
360-
361- # copy github instance with other auth
362- def with_auth (self , auth : A_o ) -> "GitHub[A_o]" :
363- return GitHub (auth = auth , config = self .config .copy ())
364-
365- # high level methods
366-
367- # rest api
368- @cached_property
369- def rest (self ) -> RestNamespace :
370- return RestNamespace (self )
371-
372- # graphql
373- def graphql (
374- self , query : str , variables : Optional [Dict [str , Any ]] = None
375- ) -> Dict [str , Any ]:
376- json = build_graphql_request (query , variables )
377-
378- return parse_graphql_response (
379- self .request ("POST" , "/graphql" , json = json , response_model = GraphQLResponse )
380- )
381-
382- async def async_graphql (
383- self , query : str , variables : Optional [Dict [str , Any ]] = None
384- ) -> Dict [str , Any ]:
385- json = build_graphql_request (query , variables )
386-
387- return parse_graphql_response (
388- await self .arequest (
389- "POST" , "/graphql" , json = json , response_model = GraphQLResponse
390- )
391- )
392-
393- # rest pagination
394- @overload
395- @staticmethod
396- def paginate (
397- request : R [CP , RT ],
398- page : int = 1 ,
399- per_page : int = 100 ,
400- map_func : None = None ,
401- * args : CP .args ,
402- ** kwargs : CP .kwargs ,
403- ) -> Paginator [RT ]:
404- ...
405-
406- @overload
407- @staticmethod
408- def paginate (
409- request : R [CP , CT ],
410- page : int = 1 ,
411- per_page : int = 100 ,
412- map_func : Callable [[Response [List [CT ]]], List [RT ]] = ..., # type: ignore
413- * args : CP .args ,
414- ** kwargs : CP .kwargs ,
415- ) -> Paginator [RT ]:
416- ...
417-
418- @staticmethod
419- def paginate (
420- request : R [CP , CT ],
421- page : int = 1 ,
422- per_page : int = 100 ,
423- map_func : Optional [Callable [[Response [List [CT ]]], List [RT ]]] = None ,
424- * args : CP .args ,
425- ** kwargs : CP .kwargs ,
426- ) -> Paginator [RT ]:
427- return Paginator (request , page , per_page , map_func , * args , ** kwargs ) # type: ignore
0 commit comments