8000 Merge pull request #678 from sigmavirus24/excise-null-obj · pythonthings/github3.py@3e251f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e251f2

Browse files
authored
Merge pull request sigmavirus24#678 from sigmavirus24/excise-null-obj
Excise NullObject from github3.py
2 parents 0ace1a7 + 9eb136d commit 3e251f2

File tree

7 files changed

+61
-134
lines changed

7 files changed

+61
-134
lines changed

github3/api.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ def login(username=None, password=None, token=None, two_factor_callback=None):
4747
4848
To allow you to specify either a username and password combination or
4949
a token, none of the parameters are required. If you provide none of
50-
them, you will receive a
51-
:class:`NullObject <github3.null.NullObject>`
50+
them, you will receive ``None``.
5251
5352
:param str username: login name
5453
:param str password: password for the login
@@ -75,8 +74,7 @@ def enterprise_login(username=None, password=None, token=None, url=None,
7574
7675
To allow you to specify either a username and password combination or
7776
a token, none of the parameters are required. If you provide none of
78-
them, you will receive a
79-
:class:`NullObject <github3.structs.NullObject>`
77+
them, you will receive ``None``.
8078
8179
:param str username: login name
8280
:param str password: password for the login

github3/github.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,7 @@ def create_issue(self, owner, repository, title, body=None, assignee=None,
284284
if owner and repository and title:
285285
repo = self.repository(owner, repository)
286286

287-
# repo can be None or a NullObject.
288-
# If repo is None, than one of owner, repository, or title were
289-
# False-y. If repo is a NullObject then owner/repository 404's.
290-
291287
if repo is not None:
292-
# If repo is a NullObject then that's most likely because the
293-
# repository was not found (404). In that case, calling the
294-
# create_issue method will still return <NullObject('Repository')>
295-
# which will ideally help the user understand what went wrong.
296288
return repo.create_issue(title, body, assignee, milestone, labels)
297289

298290
return self._instance_or_null(Issue, None)

github3/models.py

Lines changed: 1 addition & 2 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 .null import NullObject
2120
from .session import GitHubSession
2221
from .utils import UTC
2322

@@ -198,7 +197,7 @@ def _instance_or_null(self, instance_class, json):
198197
"GitHub's API returned a body that could not be handled", json
199198
)
200199
if not json:
201-
return NullObject(instance_class.__name__)
200+
return None
202201
try:
203202
return instance_class(json, self)
204203
except TypeError: # instance_class is not a subclass of GitHubCore

github3/null.py

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

tests/unit/helper.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import github3
77
import json
88
import os.path
9+
import sys
910
import pytest
1011
import unittest
1112

@@ -173,7 +174,7 @@ class has a dummy ``__iter__`` implementation which we want for
173174
# Retrieve a mocked session object
174175
session = super(UnitIteratorHelper, self).create_mocked_session(*args)
175176
# Initialize a NullObject which has magical properties
176-
null = github3.null.NullObject()
177+
null = NullObject()
177178
# Set it as the return value for every method
178179
session.delete.return_value = null
179180
session.get.return_value = null
@@ -263,3 +264,59 @@ def setUp(self):
263264
# internet
264265
self.instance._build_url = self.build_url
265266
self.after_setup()
267+
268+
269+
is_py3 = (3, 0) <= sys.version_info < (4, 0)
270+
271+
272+
class NullObject(object):
273+
def __init__(self, initializer=None):
274+
self.__dict__['initializer'] = initializer
275+
276+
def __int__(self):
277+
return 0
278+
279+
def __bool__(self):
280+
return False
281+
282+
__nonzero__ = __bool__
283+
284+
def __str__(self):
285+
return ''
286+
287+
def __unicode__(self):
288+
return '' if is_py3 else ''.decode()
289+
290+
def __repr__(self):
291+
return '<NullObject({0})>'.format(
292+
repr(self.__getattribute__('initializer'))
293+
)
294+
295+
def __getitem__(self, index):
296+
return self
297+
298+
def __setitem__(self, index, value):
299+
pass
300+
301+
def __getattr__(self, attr):
302+
return self
303+
304+
def __setattr__(self, attr, value):
305+
pass
306+
307+
def __call__(self, *args, **kwargs):
308+
return self
309+
310+
def __contains__(self, other):
311+
return False
312+
313+
def __iter__(self):
314+
return iter([])
315+
316+
def __next__(self):
317+
raise StopIteration
318+
319+
next = __next__
320+
321+
def is_null(self):
322+
return True

tests/unit/test_null.py

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

tests/unit/test_repos_repo.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from base64 import b64encode
77
from github3 import GitHubError
8-
from github3.null import NullObject
98
from github3.repos.repo import (Comparison, Contents, Hook, RepoComment,
109
RepoCommit, Repository)
1110
from github3.models import GitHubCore
@@ -80,7 +79,6 @@ def test_add_collaborator(self):
8079
def test_add_null_collaborator(self):
8180
"""Verify no request is made when adding `None` as a collaborator."""
8281
self.instance.add_collaborator(None)
83-
self.instance.add_collaborator(NullObject())
8482

8583
assert self.session.put.called is False
8684

0 commit comments

Comments
 (0)
0