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

Commit3e251f2

Browse files
authored
Merge pull requestsigmavirus24#678 from sigmavirus24/excise-null-obj
Excise NullObject from github3.py
2 parents0ace1a7 +9eb136d commit3e251f2

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
ifownerandrepositoryandtitle:
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
ifrepoisnotNone:
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
returnrepo.create_issue(title,body,assignee,milestone,labels)
297289

298290
returnself._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 .importexceptions
1919
from .decoratorsimportrequires_auth
20-
from .nullimportNullObject
2120
from .sessionimportGitHubSession
2221
from .utilsimportUTC
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
ifnotjson:
201-
returnNullObject(instance_class.__name__)
200+
returnNone
202201
try:
203202
returninstance_class(json,self)
204203
exceptTypeError:# 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
importgithub3
77
importjson
88
importos.path
9+
importsys
910
importpytest
1011
importunittest
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+
classNullObject(object):
273+
def__init__(self,initializer=None):
274+
self.__dict__['initializer']=initializer
275+
276+
def__int__(self):
277+
return0
278+
279+
def__bool__(self):
280+
returnFalse
281+
282+
__nonzero__=__bool__
283+
284+
def__str__(self):
285+
return''
286+
287+
def__unicode__(self):
288+
return''ifis_py3else''.decode()
289+
290+
def__repr__(self):
291+
return'<NullObject({0})>'.format(
292+
repr(self.__getattribute__('initializer'))
293+
)
294+
295+
def__getitem__(self,index):
296+
returnself
297+
298+
def__setitem__(self,index,value):
299+
pass
300+
301+
def__getattr__(self,attr):
302+
returnself
303+
304+
def__setattr__(self,attr,value):
305+
pass
306+
307+
def__call__(self,*args,**kwargs):
308+
returnself
309+
310+
def__contains__(self,other):
311+
returnFalse
312+
313+
def__iter__(self):
314+
returniter([])
315+
316+
def__next__(self):
317+
raiseStopIteration
318+
319+
next=__next__
320+
321+
defis_null(self):
322+
returnTrue

‎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
frombase64importb64encode
77
fromgithub3importGitHubError
8-
fromgithub3.nullimportNullObject
98
fromgithub3.repos.repoimport (Comparison,Contents,Hook,RepoComment,
109
RepoCommit,Repository)
1110
fromgithub3.modelsimportGitHubCore
@@ -80,7 +79,6 @@ def test_add_collaborator(self):
8079
deftest_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
assertself.session.put.calledisFalse
8684

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp