8000 Merge pull request #676 from sigmavirus24/eliminate-empty · guicalman/github3.py@0ace1a7 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 0ace1a7

Browse files
authored
Merge pull request sigmavirus24#676 from sigmavirus24/eliminate-empty
Excise github3.empty.Empty
2 parents b0b27c4 + 10d625b commit 0ace1a7

22 files changed

+45
-110
lines changed

docs/empty.rst

Lines changed: 0 additions & 13 deletions
This file was deleted.

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ Modules
6868

6969
api
7070
auths
71-
empty
7271
events
7372
gists
7473
git

github3/empty.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

github3/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _update_attributes(self, event):
6060

6161
#: Return ``tuple(owner, repository_name)``
6262
self.repo = self._get_attribute(event, 'repo')
63-
if self.repo and self.repo is not self.Empty:
63+
if self.repo:
6464
self.repo = tuple(self.repo['name'].split('/'))
6565

6666
#: Indicates whether the Event is public or not.

github3/gists/gist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _update_attributes(self, data):
4545

4646
#: Unique id for this gist.
4747
self.data = self._get_attribute(data, 'id')
48-
if self.data and self.data is not self.Empty:
48+
if self.data:
4949
self.data = '{0}'.format(data['id'])
5050

5151
#: Description of the gist
@@ -78,13 +78,13 @@ def _update_attributes(self, data):
7878
self.owner = self._class_attribute(data, 'owner', User, self)
7979

8080
self._files = self._get_attribute(data, 'files', [])
81-
if self._files and self._files is not self.Empty:
81+
if self._files:
8282
self._files = [GistFile(self._files[f]) for f in self._files]
8383

8484
#: History of this gist, list of
8585
#: :class:`GistHistory <github3.gists.history.GistHistory>`
8686
self.history = self._get_attribute(data, 'history', [])
87-
if self.history and self.history is not self.Empty:
87+
if self.history:
8888
self.history = [GistHistory(h, self) for h in self.history]
8989

9090
# New urls

github3/git.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ def _update_attributes(self, blob):
2929

3030
#: Raw content of the blob.
3131
self.content = self._get_attribute(blob, 'content')
32-
if self.content is not None and self.content is not self.Empty:
32+
if self.content is not None:
3333
self.content = self.content.encode()
3434

3535
#: Encoding of the raw content.
3636
self.encoding = self._get_attribute(blob, 'encoding')
3737

3838
#: Decoded content of the blob.
3939
self.decoded = self.content
40-
if self.encoding == 'base64' and self.content is not self.Empty:
40+
if self.encoding == 'base64':
4141
self.decoded = b64decode(self.content)
4242

4343
#: Size of the blob in bytes
@@ -217,7 +217,7 @@ def _update_attributes(self, tree):
217217

218218
#: list of :class:`Hash <Hash>` objects
219219
self.tree = self._get_attribute(tree, 'tree', [])
220-
if self.tree and self.tree is not self.Empty:
220+
if self.tree:
221221
self.tree = [Hash(t) for t in self.tree]
222222

223223
def _repr(self):

github3/issues/issue.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _update_attributes(self, issue):
4040
#: was assigned to.
4141
self.assignee = self._class_attribute(issue, 'assignee', User, self)
4242
self.assignees = self._get_attribute(issue, 'assignees')
43-
if self.assignees is not self.Empty:
43+
if self.assignees:
4444
self.assignees = [
4545
User(assignee) for assignee in self.assignees
4646
]
@@ -79,7 +79,7 @@ def _update_attributes(self, issue):
7979
#: Returns the list of :class:`Label <github3.issues.label.Label>`\ s
8080
#: on this issue.
8181
self.original_labels = self._get_attribute(issue, 'labels', [])
82-
if self.original_labels and self.original_labels is not self.Empty:
82+
if self.original_labels:
8383
self.original_labels = [
8484
Label(l, self) for l in self.original_labels
8585
]
@@ -104,8 +104,8 @@ def _update_attributes(self, issue):
104104
self.pull_request_urls = self._get_attribute(issue, 'pull_request', {})
105105

106106
#: Returns ('owner', 'repository') this issue was filed on.
107-
self.repository = self.Empty
108-
if self.html_url and self.html_url is not self.Empty:
107+
self.repository = None
108+
if self.html_url:
109109
m = match('https?://[\w\d\-\.\:]+/(\S+)/(\S+)/(?:issues|pull)/\d+',
110110
self.html_url)
111111
self.repository = m.groups()

github3/models.py

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from . import exceptions
1919
from .decorators import requires_auth
20-
from .empty import Empty
2120
from .null import NullObject
2221
from .session import GitHubSession
2322
from .utils import UTC
@@ -27,17 +26,13 @@
2726

2827

2928
class GitHubCore(object):
30-
3129
"""The base object for all objects that require a session.
3230
3331
The :class:`GitHubCore <GitHubCore>` object provides some
3432
basic attributes and methods to other sub-classes that are very useful to
3533
have.
3634
"""
3735

38-
# Set the Empty singleton so model.Empty can be used.
39-
Empty = Empty
40-
4136
def __init__(self, json, session=None):
4237
if hasattr(session, 'session'):
4338
# i.e. session is actually a GitHubCore instance
@@ -49,7 +44,7 @@ def __init__(self, json, session=None):
4944
# set a sane default
5045
self._github_url = 'https://api.github.com'
5146

52-
if json is not None and json is not self.Empty:
47+
if json is not None:
5348
self.etag = json.pop('ETag', None)
5449
self.last_modified = json.pop('Last-Modified', None)
5550
self._uniq = json.get('url', None)
@@ -95,31 +90,30 @@ def as_json(self):
9590
def _get_attribute(cls, data, attribute, fallback=None):
9691
"""Return the attribute from the json data.
9792
98-
:param dict data: dictionary used to put together the model or Empty
93+
:param dict data: dictionary used to put together the model
9994
:param str attribute: key of the attribute
10095
:param any fallback: return value if original return value is falsy
101-
:returns: value paired with key in dict, Empty or fallback
102-
:rtype: any or Empty
96+
:returns: value paired with key in dict, fallback
10397
"""
104-
if data is not cls.Empty and attribute in data:
105-
result = data[attribute]
106-
if result is None:
107-
return fallback
108-
return result
109-
return cls.Empty
98+
if data is None or not isinstance(data, dict):
99+
return None
100+
result = data.get(attribute)
101+
if result is None:
102+
return fallback
103+
return result
110104

111105
@classmethod
112106
def _class_attribute(cls, data, attribute, cl, *args, **kwargs):
113107
"""Return the attribute from the json data and instantiate the class.
114108
115-
:param dict data: dictionary used to put together the model or Empty
109+
:param dict data: dictionary used to put together the model or None
116110
:param str attribute: key of the attribute
117111
:param class cl: class that will be instantiated
118-
:returns: instantiated class or Empty
119-
:rtype: object or Empty
112+
:returns: instantiated class or None
113+
:rtype: object or None
120114
"""
121115
value = cls._get_attribute(data, attribute)
122-
if value and value is not cls.Empty:
116+
if value:
123117
return cl(
124118
value,
125119
*args,
@@ -129,19 +123,19 @@ def _class_attribute(cls, data, attribute, cl, *args, **kwargs):
129123

130124
@classmethod
131125
def _strptime_attribute(cls, data, attribute):
132-
"""Get a datetime object from a dict, return Empty if it wan't found.
126+
"""Get a datetime object from a dict, return None if it wan't found.
133127
134128
This is equivalent to calling::
135129
136-
cls._strptime(data[attribute]) if attribute in data else Empty
130+
cls._strptime(data[attribute]) if attribute in data else None
137131
138-
:param dict data: dictionary used to put together the model or Empty
132+
:param dict data: dictionary used to put together the model
139133
:param str attribute: key of the attribute
140-
:returns: timezone-aware datetime object or Empty
141-
:rtype: datetime or Empty
134+
:returns: timezone-aware datetime object
135+
:rtype: datetime
142136
"""
143137
result = cls._get_attribute(data, attribute)
144-
if result and result is not cls.Empty:
138+
if result:
145139
return cls._strptime(result)
146140
return result
147141

@@ -283,7 +277,7 @@ def _api(self):
283277

284278
@_api.setter
285279
def _api(self, uri):
286-
if uri and uri is not self.Empty:
280+
if uri:
287281
self._uri = urlparse(uri)
288282
self.url = uri
289283

@@ -384,7 +378,7 @@ def _update_attributes(self, comment):
384378

385379
#: The url of the pull request, if it exists
386380
self.pull_request_url = ''
387-
if self.links and self.links is not self.Empty:
381+
if self.links:
388382
self.html_url = self.links.get('html')
389383
self.pull_request_url = self.links.get('pull_request')
390384

@@ -435,7 +429,7 @@ def _update_attributes(self, commit):
435429

436430
#: URL to view the commit on GitHub
437431
self.html_url = self._get_attribute(commit, 'html_url')
438-
if not self.sha or self.sha is self.Empty:
432+
if not self.sha:
439433
i = self._api.rfind('/')
440434
self.sha = self._api[i + 1:]
441435

github3/orgs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,10 @@ def _update_attributes(self, membership):
647647

648648
self.state = self._get_attribute(membership, 'state')
649649
self.active = self.state
650-
if self.active and self.active is not self.Empty:
650+
if self.active:
651651
self.active = self.state.lower() == 'active'
652652
self.pending = self.state
653-
if self.pending and self.pending is not self.Empty:
653+
if self.pending:
654654
self.pending = self.state.lower() == 'pending'
655655

656656
@requires_auth

github3/pulls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _update_attributes(self, pull):
223223

224224
#: Returns ('owner', 'repository') this issue was filed on.
225225
self.repository = self.base
226-
if self.repository and self.repository is not self.Empty:
226+
if self.repository:
227227
self.repository = self.base.repo
228228

229229
#: The state of the pull

0 commit comments

Comments
 (0)
0