8000 Use ShortUser where appropriate · pythonthings/github3.py@e098c81 · GitHub
[go: up one dir, main page]

Skip to content

Commit e098c81

Browse files
committed
Use ShortUser where appropriate
1 parent 5c94d61 commit e098c81

File tree

6 files changed

+45
-31
lines changed

6 files changed

+45
-31
lines changed

github3/gists/comment.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"""
99
from __future__ import unicode_literals
1010

11+
from .. import users
1112
from ..models import BaseComment
12-
from ..users import User
1313

1414

1515
class GistComment(BaseComment):
@@ -34,7 +34,9 @@ def _update_attributes(self, comment):
3434
self._api = self._get_attribute(comment, 'url')
3535
#: :class:`User <github3.users.User>` who made the comment
3636
#: Unless it is not associated with an account
37-
self.user = self._class_attribute(comment, 'user', User, self)
37+
self.user = self._class_attribute(
38+
comment, 'user', users.ShortUser, self,
39+
)
3840

3941
def _repr(self):
4042
return '<Gist Comment [{0}]>'.format(self.user.login)

github3/gists/gist.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
from __future__ import unicode_literals
1010

1111
from json import dumps
12+
13+
from .. import users
14+
1215
from ..models import GitHubCore
1316
from ..decorators import requires_auth
1417
from .comment import GistComment
1518
from .file import GistFile
1619
from .history import GistHistory
17-
from ..users import User
1820

1921

2022
class Gist(GitHubCore):
@@ -75,7 +77,9 @@ def _update_attributes(self, data):
7577

7678
#: :class:`User <github3.users.User>` object representing the owner of
7779
#: the gist.
78-
self.owner = self._class_attribute(data, 'owner', User, self)
80+
self.owner = self._class_attribute(
81+
data, 'owner', users.ShortUser, self,
82+
)
7983

8084
self._files = self._get_attribute(data, 'files', [])
8185
if self._files:

github3/gists/history.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"""
99
from __future__ import unicode_literals
1010

11+
from .. import users
1112
from ..models import GitHubCore
12-
from ..users import User
1313

1414

1515
class GistHistory(GitHubCore):
@@ -35,7 +35,9 @@ def _update_attributes(self, history):
3535
self.version = self._get_attribute(history, 'version')
3636

3737
#: user who made these changes
38-
self.user = self._class_attribute(history, 'user', User, self)
38+
self.user = self._class_attribute(
39+
history, 'user', users.ShortUser, self,
40+
)
3941

4042
#: dict containing the change status; see also: deletions, additions,
4143
#: total

github3/issues/issue.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
from uritemplate import URITemplate
88

9+
from .. import users
10+
911
from ..decorators import requires_auth
1012
from ..models import GitHubCore
11-
from ..users import User
1213
from .comment import IssueComment, issue_comment_params
1314
from .event import IssueEvent
1415
from .label import Label
@@ -38,11 +39,12 @@ def _update_attributes(self, issue):
3839

3940
#: :class:`User <github3.users.User>` representing the user the issue
4041
#: was assigned to.
41-
self.assignee = self._class_attribute(issue, 'assignee', User, self)
42+
self.assignee = self._class_attribute(
43+
issue, 'assignee', users.ShortUser, self)
4244
self.assignees = self._get_attribute(issue, 'assignees')
4345
if self.assignees:
4446
self.assignees = [
45-
User(assignee) for assignee in self.assignees
47+
users.ShortUser(assignee) for assignee in self.assignees
4648
]
4749

4850
#: Body (description) of the issue.
@@ -120,10 +122,12 @@ def _update_attributes(self, issue):
120122
self.updated_at = self._strptime_attribute(issue, 'updated_at')
121123

122124
#: :class:`User <github3.users.User>` who opened the issue.
123-
self.user = self._class_attribute(issue, 'user', User, self)
125+
self.user = self._class_attribute(
126+
issue, 'user', users.ShortUser, self)
124127

125128
#: :class:`User <github3.users.User>` who closed the issue.
126-
self.closed_by = self._class_attribute(issue, 'closed_by', User, self)
129+
self.closed_by = self._class_attribute(
130+
issue, 'closed_by', users.ShortUser, self)
127131

128132
def _repr(self):
129133
return '<Issue [{r[0]}/{r[1]} #{n}]>'.format(r=self.repository,

github3/repos/repo.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
from uritemplate import URITemplate
1616

17+
from .. import users
18+
1719
from ..decorators import requires_auth
1820
from ..events import Event
1921
from ..git import Blob, Commit, Reference, Tag, Tree
@@ -25,7 +27,6 @@
2527
from ..models import GitHubCore
2628
from ..notifications import Subscription, Thread
2729
from ..pulls import PullRequest
28-
from ..users import Key, User
2930
from ..utils import stream_response_to_file, timestamp_parameter
3031
from .branch import Branch
3132
from .comment import RepoComment
@@ -141,7 +142,8 @@ def _update_attributes(self, repo):
141142
# Repository owner's name
142143
#: :class:`User <github3.users.User>` object representing the
143144
#: repository owner.
144-
self.owner = self._class_attribute(repo, 'owner', User, self)
145+
self.owner = self._class_attribute(
146+
repo, 'owner', users.ShortUser, self)
145147

146148
#: Is this repository private?
147149
self.private = self._get_attribute(repo, 'private')
@@ -451,10 +453,10 @@ def assignees(self, number=-1, etag=None):
451453
-1 returns all available assignees
452454
:param str etag: (optional), ETag from a previous request to the same
453455
endpoint
454-
:returns: generator of :class:`User <github3.users.User>`\ s
456+
:returns: generator of :class:`~github3.users.User`\ s
455457
"""
456458
url = self._build_url('assignees', base_url=self._api)
457-
return self._iter(int(number), url, User, etag=etag)
459+
return self._iter(int(number), url, users.ShortUser, etag=etag)
458460

459461
def blob(self, sha):
460462
"""Get the blob indicated by ``sha``.
@@ -529,10 +531,10 @@ def collaborators(self, number=-1, etag=None):
529531
Default: 10000 -1 returns all comments
530532
:param str etag: (optional), ETag from a previous request to the same
531533
endpoint
532-
:returns: generator of :class:`User <github3.users.User>`\ s
534+
:returns: generator of :class:`~github3.users.ShortUser`\ s
533535
"""
534536
url = self._build_url('collaborators', base_url=self._api)
535-
return self._iter(int(number), url, User, etag=etag)
537+
return self._iter(int(number), url, users.ShortUser, etag=etag)
536538

537539
def comments(self, number=-1, etag=None):
538540
r"""Iterate over comments on all commits in the repository.
@@ -672,13 +674,13 @@ def contributors(self, anon=False, number=-1, etag=None):
672674
Default: -1 returns all contributors
673675
:param str etag: (optional), ETag from a previous request to the same
674676
endpoint
675-
:returns: generator of :class:`User <github3.users.User>`\ s
677+
:returns: generator of :class:`~github3.users.ShortUser`\ s
676678
"""
677679
url = self._build_url('contributors', base_url=self._api)
678680
params = {}
679681
if anon:
680682
params = {'anon': 'true'}
681-
return self._iter(int(number), url, User, params, etag)
683+
return self._iter(int(number), url, users.ShortUser, params, etag)
682684

683685
@requires_auth
684686
def create_blob(self, content, encoding):
@@ -911,14 +913,14 @@ def create_key(self, title, key, read_only=False):
911913
:param str key: (required), key text
912914
:param bool read_only: (optional), restrict key access to read-only,
913915
default is False
914-
:returns: :class:`Key <github3.users.Key>` if successful, else None
916+
:returns: :class:`~github3.users.Key` if successful, else None
915917
"""
916918
json = None
917919
if title and key:
918920
data = {'title': title, 'key': key, 'read_only': read_only}
919921
url = self._build_url('keys', base_url=self._api)
920922
json = self._json(self._post(url, data=data), 201)
921-
return self._instance_or_null(Key, json)
923+
return self._instance_or_null(users.Key, json)
922924

923925
@requires_auth
924926
def create_label(self, name, color):
@@ -1530,13 +1532,13 @@ def key(self, id_num):
15301532
"""Get the specified deploy key.
15311533
15321534
:param int id_num: (required), id of the key
1533-
:returns: :class:`Key <github3.users.Key>` if successful, else None
1535+
:returns: :class:`~github3.users.Key` if successful, else None
15341536
"""
15351537
json = None
15361538
if int(id_num) > 0:
15371539
url = self._build_url('keys', str(id_num), base_url=self._api)
15381540
json = self._json(self._get(url), 200)
1539-
return Key(json, self) if json else None
1541+
return users.Key(json, self) if json else None
15401542

15411543
@requires_auth
15421544
def keys(self, number=-1, etag=None):
@@ -1546,10 +1548,10 @@ def keys(self, number=-1, etag=None):
15461548
returns all available keys
15471549
:param str etag: (optional), ETag from a previous request to the same
15481550
endpoint
1549-
:returns: generator of :class:`Key <github3.users.Key>`\ s
1551+
:returns: generator of :class:`~github3.users.Key`\ s
15501552
"""
15511553
url = self._build_url('keys', base_url=self._api)
1552-
return self._iter(int(number), url, Key, etag=etag)
1554+
return self._iter(int(number), url, users.Key, etag=etag)
15531555

15541556
def label(self, name):
15551557
"""Get the label specified by ``name``.
@@ -1912,10 +1914,10 @@ def stargazers(self, number=-1, etag=None):
19121914
Default: -1 returns all subscribers available
19131915
:param str etag: (optional), ETag from a previous request to the same
19141916
endpoint
1915-
:returns: generator of :class:`User <github3.users.User>`\ s
1917+
:returns: generator of :class:`~github3.users.ShortUser`\ s
19161918
"""
19171919
url = self._build_url('stargazers', base_url=self._api)
1918-
return self._iter(int(number), url, User, etag=etag)
1920+
return self._iter(int(number), url, users.ShortUser, etag=etag)
19191921

19201922
def statuses(self, sha, number=-1, etag=None):
19211923
r"""Iterate over the statuses for a specific SHA.
@@ -1963,10 +1965,10 @@ def subscribers(self, number=-1, etag=None):
19631965
Default: -1 returns all subscribers available
19641966
:param str etag: (optional), ETag from a previous request to the same
19651967
endpoint
1966-
:returns: generator of :class:`User <github3.users.User>`
1968+
:returns: generator of :class:`~github3.users.ShortUser`
19671969
"""
19681970
url = self._build_url('subscribers', base_url=self._api)
1969-
return self._iter(int(number), url, User, etag=etag)
1971+
return self._iter(int(number), url, users.ShortUser, etag=etag)
19701972

19711973
@requires_auth
19721974
def subscription(self):

github3/search/user.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4+
from .. import users
45
from ..models import GitHubCore
5-
from ..users import User
66

77

88
class UserSearchResult(GitHubCore):
@@ -20,7 +20,7 @@ def _update_attributes(self, data):
2020
del result['text_matches']
2121

2222
#: User object matching the search
23-
self.user = User(result, self)
23+
self.user = users.ShortUser(result, self)
2424

2525
def _repr(self):
2626
return '<UserSearchResult [{0}]>'.format(self.user)

0 commit comments

Comments
 (0)
0