Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda2989c

Browse files
committed
Stub out our universal base class
Experiment with Generics for the refresh method. And see how far thatgets us.
1 parent8c5b3e9 commitda2989c

File tree

3 files changed

+159
-33
lines changed

3 files changed

+159
-33
lines changed

‎github3/github.pyi‎

Lines changed: 86 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,90 @@
11
"""This module contains the type stubs for github3.github."""
2-
fromtypingimportDict,List,Union,Optional
2+
fromtypingimport (
3+
Any,
4+
Dict,
5+
List,
6+
Optional,
7+
TypeVar,
8+
Union,
9+
)
310

411
from .importauths
512
from .importevents
6-
from .gistsimportgist
7-
from .issuesimportissue
13+
from .importmodels
814
from .importorgs
9-
from .reposimportrepo
1015
from .importstructs
1116
from .importusers
17+
from .gistsimportgist
18+
from .issuesimportissue
19+
from .reposimportrepo
1220

13-
AuthorizationsIterator=structs.GitHubIterator[auths.Authorization]
14-
EventsIterator=structs.GitHubIterator[events.Event]
15-
OrganizationsIterator=structs.GitHubIterator[orgs.ShortOrganization]
16-
RepositoriesIterator=structs.GitHubIterator[repo.ShortRepository]
17-
UsersIterator=structs.GitHubIterator[users.ShortUser]
21+
T=TypeVar('T',bound='GitHub')
1822

1923

20-
classGitHub:
24+
classGitHub(models.GitHubCore):
2125
def__init__(
22-
self,
26+
self:T,
2327
username:str='',
2428
password:str='',
2529
token:str='',
2630
)->None:
2731
...
2832

2933
defadd_email_addresses(
30-
self,
34+
self:T,
3135
addresses:List[str]=[],
3236
)->List[users.Email]:
3337
...
3438

3539
defall_events(
36-
self,
40+
self:T,
3741
number:int=-1,
3842
etag:Optional[str]=None,
39-
)->EventsIterator:
43+
)->structs.GitHubIterator[events.Event]:
4044
...
4145

4246
defall_organizations(
43-
self,
47+
self:T,
4448
number:int=-1,
4549
since:Optional[int]=None,
4650
etag:Optional[str]=None,
4751
per_page:Optional[int]=None,
48-
)->OrganizationsIterator:
52+
)->structs.GitHubIterator[orgs.ShortOrganization]:
4953
...
5054

5155
defall_repositories(
52-
self,
56+
self:T,
5357
number:int=-1,
5458
since:Optional[int]=None,
5559
etag:Optional[str]=None,
5660
per_page:Optional[int]=None,
57-
)->RepositoriesIterator:
61+
)->structs.GitHubIterator[repo.ShortRepository]:
5862
...
5963

6064
defall_users(
61-
self,
65+
self:T,
6266
number:int=-1,
6367
etag:Optional[str]=None,
6468
per_page:Optional[int]=None,
6569
since:Optional[int]=None,
66-
)->UsersIterator:
70+
)->structs.GitHubIterator[users.ShortUser]:
6771
...
6872

6973
defauthorization(
70-
self,
74+
self:T,
7175
id_num:Union[int,str],
72-
)->AuthorizationsIterator:
76+
)->auths.Authorization:
7377
...
7478

7579
defauthorizations(
76-
self,
80+
self:T,
7781
number:int=-1,
7882
etag:Optional[str]=None,
79-
)->AuthorizationsIterator:
83+
)->structs.GitHubIterator[auths.Authorization]:
8084
...
8185

8286
defauthorize(
83-
self,
87+
self:T,
8488
username:str,
8589
password:str,
8690
scopes:Optional[List[str]]=None,
@@ -92,21 +96,21 @@ class GitHub:
9296
...
9397

9498
defcheck_authorization(
95-
self,
99+
self:T,
96100
access_token:str,
97101
)->bool:
98102
...
99103

100104
defcreate_gist(
101-
self,
105+
self:T,
102106
description:str,
103107
files:Dict[str,Dict[str,str]],
104108
public:bool=True,
105109
)->gist.Gist:
106110
...
107111

108112
defcreate_issue(
109-
self,
113+
self:T,
110114
owner:str,
111115
repository:str,
112116
title:str,
@@ -117,3 +121,57 @@ class GitHub:
117121
assignees:Optional[List[str]]=None,
118122
)->issue.ShortIssue:
119123
...
124+
125+
defcreate_key(
126+
self:T,
127+
title:str,
128+
key:str,
129+
read_only:bool=False,
130+
)->users.Key:
131+
...
132+
133+
defcreate_repository(
134+
self:T,
135+
name:str,
136+
description:str='',
137+
homepage:str='',
138+
private:bool=False,
139+
has_issues:bool=True,
140+
has_wiki:bool=True,
141+
auto_init:bool=False,
142+
gitignore_template:str='',
143+
)->repo.Repository:
144+
...
145+
146+
defdelete_email_addresses(
147+
self:T,
148+
addresses:List[str],
149+
)->bool:
150+
...
151+
152+
defemails(
153+
self:T,
154+
number:int=-1,
155+
etag:Optional[str]=None,
156+
)->structs.GitHubIterator[users.Email]:
157+
...
158+
159+
defemojis(self:T)->Dict[str,str]:
160+
...
161+
162+
deffeeds(self:T)->Dict[str,Any]:
163+
...
164+
165+
deffollow(
166+
self:T,
167+
username:str
168+
)->bool:
169+
...
170+
171+
deffollowed_by(
172+
self:T,
173+
username:str,
174+
number:int=-1,
175+
etag:Optional[str]=None,
176+
)->structs.GitHubIterator[users.ShortUser]:
177+
...

‎github3/models.pyi‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
fromtypingimport (
2+
Any,
3+
Dict,
4+
Generic,
5+
Optional,
6+
Type,
7+
TypeVar,
8+
Union,
9+
)
10+
11+
from .importsession
12+
13+
14+
Subclass=TypeVar('Subclass',bound='GitHubCore')
15+
Core=TypeVar('Core',bound='GitHubCore')
16+
Sessionish=Union[session.GitHubSession,GitHubCore]
17+
FullClass=TypeVar('FullClass')
18+
19+
classGitHubCore(Generic[FullClass]):
20+
_refresh_to=None# type: Optional[FullClass]
21+
22+
def__init__(
23+
self:Core,
24+
json:Dict[str,Any],
25+
session:Sessionish,
26+
)->None:
27+
...
28+
29+
defas_dict(self:Core)->Dict[str,Any]:
30+
...
31+
32+
defas_json(self:Core)->str:
33+
...
34+
35+
@classmethod
36+
deffrom_dict(
37+
cls:Type[Subclass],
38+
json_dict:Dict[str,Any],
39+
session:Sessionish,
40+
)->Subclass:
41+
...
42+
43+
@classmethod
44+
deffrom_json(
45+
cls:Type[Subclass],
46+
json_dict:str,
47+
session:Sessionish,
48+
)->Subclass:
49+
...
50+
51+
@property
52+
defratelimit_remaining(self:Core)->int:
53+
...
54+
55+
defrefresh(
56+
self:Core,
57+
conditional:bool,
58+
)->Union[Core,FullClass]:
59+
...
60+
61+
defnew_session(self:Core)->session.GitHubSession:
62+
...

‎github3/users.pyi‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
class_User:
2-
...
3-
1+
from .importmodels
42

5-
classShortUser(_User):
3+
class_User(models.GitHubCore):
64
...
75

86

97
classUser(_User):
108
...
119

1210

11+
classShortUser(_User):
12+
_refresh_to=User
13+
14+
1315
classContributor(_User):
1416
...
1517

@@ -18,5 +20,9 @@ class AuthenticatedUser(User):
1820
...
1921

2022

21-
classEmail:
23+
classEmail(models.GitHubCore):
24+
...
25+
26+
27+
classKey(models.GitHubCore):
2228
...

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp