mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-01 11:21:16 +00:00
Improve type asserts on lists
This commit is contained in:
@@ -177,7 +177,7 @@ class AuthenticatedUser( object ):
|
||||
|
||||
def create_authorization( self, scopes = DefaultValueForOptionalParameters, note = DefaultValueForOptionalParameters, note_url = DefaultValueForOptionalParameters ):
|
||||
if scopes is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( scopes, list ) and ( len( scopes ) == 0 or isinstance( scopes[ 0 ], ( str, unicode ) ) ), scopes
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in scopes ), scopes
|
||||
if note is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( note, ( str, unicode ) ), note
|
||||
if note_url is not DefaultValueForOptionalParameters:
|
||||
@@ -559,7 +559,7 @@ class AuthenticatedUser( object ):
|
||||
return status == 204
|
||||
|
||||
def remove_from_emails( self, *emails ):
|
||||
assert len( emails ) == 0 or isinstance( emails[ 0 ], ( str, unicode ) ), emails
|
||||
assert all( isinstance( email, ( str, unicode ) ) for email in emails ), emails
|
||||
post_parameters = emails
|
||||
status, headers, data = self.__requester.request(
|
||||
"DELETE",
|
||||
|
||||
@@ -69,11 +69,11 @@ class Authorization( object ):
|
||||
|
||||
def edit( self, scopes = DefaultValueForOptionalParameters, add_scopes = DefaultValueForOptionalParameters, remove_scopes = DefaultValueForOptionalParameters, note = DefaultValueForOptionalParameters, note_url = DefaultValueForOptionalParameters ):
|
||||
if scopes is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( scopes, list ) and ( len( scopes ) == 0 or isinstance( scopes[ 0 ], ( str, unicode ) ) ), scopes
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in scopes ), scopes
|
||||
if add_scopes is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( add_scopes, list ) and ( len( add_scopes ) == 0 or isinstance( add_scopes[ 0 ], ( str, unicode ) ) ), add_scopes
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in add_scopes ), add_scopes
|
||||
if remove_scopes is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( remove_scopes, list ) and ( len( remove_scopes ) == 0 or isinstance( remove_scopes[ 0 ], ( str, unicode ) ) ), remove_scopes
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in remove_scopes ), remove_scopes
|
||||
if note is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( note, ( str, unicode ) ), note
|
||||
if note_url is not DefaultValueForOptionalParameters:
|
||||
@@ -139,7 +139,7 @@ class Authorization( object ):
|
||||
assert isinstance( attributes[ "note_url" ], ( str, unicode ) ), attributes[ "note_url" ]
|
||||
self.__note_url = attributes[ "note_url" ]
|
||||
if "scopes" in attributes and attributes[ "scopes" ] is not None: # pragma no branch
|
||||
assert isinstance( attributes[ "scopes" ], list ) and ( len( attributes[ "scopes" ] ) == 0 or isinstance( attributes[ "scopes" ][ 0 ], ( str, unicode ) ) ), attributes[ "scopes" ]
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in attributes[ "scopes" ] ), attributes[ "scopes" ]
|
||||
self.__scopes = attributes[ "scopes" ]
|
||||
if "token" in attributes and attributes[ "token" ] is not None: # pragma no branch
|
||||
assert isinstance( attributes[ "token" ], ( str, unicode ) ), attributes[ "token" ]
|
||||
|
||||
@@ -133,13 +133,13 @@ class Commit( object ):
|
||||
assert isinstance( attributes[ "committer" ], dict ), attributes[ "committer" ]
|
||||
self.__committer = NamedUser.NamedUser( self.__requester, attributes[ "committer" ], completion = LazyCompletion )
|
||||
if "files" in attributes and attributes[ "files" ] is not None: # pragma no branch
|
||||
assert isinstance( attributes[ "files" ], list ) and ( len( attributes[ "files" ] ) == 0 or isinstance( attributes[ "files" ][ 0 ], dict ) ), attributes[ "files" ]
|
||||
assert all( isinstance( element, dict ) for element in attributes[ "files" ] ), attributes[ "files" ]
|
||||
self.__files = [
|
||||
CommitFile.CommitFile( self.__requester, element, completion = LazyCompletion )
|
||||
for element in attributes[ "files" ]
|
||||
]
|
||||
if "parents" in attributes and attributes[ "parents" ] is not None: # pragma no branch
|
||||
assert isinstance( attributes[ "parents" ], list ) and ( len( attributes[ "parents" ] ) == 0 or isinstance( attributes[ "parents" ][ 0 ], dict ) ), attributes[ "parents" ]
|
||||
assert all( isinstance( element, dict ) for element in attributes[ "parents" ] ), attributes[ "parents" ]
|
||||
self.__parents = [
|
||||
Commit( self.__requester, element, completion = LazyCompletion )
|
||||
for element in attributes[ "parents" ]
|
||||
|
||||
+2
-2
@@ -234,7 +234,7 @@ class Gist( object ):
|
||||
assert isinstance( attributes[ "fork_of" ], dict ), attributes[ "fork_of" ]
|
||||
self.__fork_of = Gist( self.__requester, attributes[ "fork_of" ], completion = LazyCompletion )
|
||||
if "forks" in attributes and attributes[ "forks" ] is not None: # pragma no branch
|
||||
assert isinstance( attributes[ "forks" ], list ) and ( len( attributes[ "forks" ] ) == 0 or isinstance( attributes[ "forks" ][ 0 ], dict ) ), attributes[ "forks" ]
|
||||
assert all( isinstance( element, dict ) for element in attributes[ "forks" ] ), attributes[ "forks" ]
|
||||
self.__forks = [
|
||||
Gist( self.__requester, element, completion = LazyCompletion )
|
||||
for element in attributes[ "forks" ]
|
||||
@@ -246,7 +246,7 @@ class Gist( object ):
|
||||
assert isinstance( attributes[ "git_push_url" ], ( str, unicode ) ), attributes[ "git_push_url" ]
|
||||
self.__git_push_url = attributes[ "git_push_url" ]
|
||||
if "history" in attributes and attributes[ "history" ] is not None: # pragma no branch
|
||||
assert isinstance( attributes[ "history" ], list ) and ( len( attributes[ "history" ] ) == 0 or isinstance( attributes[ "history" ][ 0 ], dict ) ), attributes[ "history" ]
|
||||
assert all( isinstance( element, dict ) for element in attributes[ "history" ] ), attributes[ "history" ]
|
||||
self.__history = [
|
||||
GistHistoryState.GistHistoryState( self.__requester, element, completion = LazyCompletion )
|
||||
for element in attributes[ "history" ]
|
||||
|
||||
@@ -61,7 +61,7 @@ class GitCommit( object ):
|
||||
assert isinstance( attributes[ "message" ], ( str, unicode ) ), attributes[ "message" ]
|
||||
self.__message = attributes[ "message" ]
|
||||
if "parents" in attributes and attributes[ "parents" ] is not None: # pragma no branch
|
||||
assert isinstance( attributes[ "parents" ], list ) and ( len( attributes[ "parents" ] ) == 0 or isinstance( attributes[ "parents" ][ 0 ], dict ) ), attributes[ "parents" ]
|
||||
assert all( isinstance( element, dict ) for element in attributes[ "parents" ] ), attributes[ "parents" ]
|
||||
self.__parents = [
|
||||
GitCommit( self.__requester, element, completion = LazyCompletion )
|
||||
for element in attributes[ "parents" ]
|
||||
|
||||
@@ -33,7 +33,7 @@ class GitTree( object ):
|
||||
assert isinstance( attributes[ "sha" ], ( str, unicode ) ), attributes[ "sha" ]
|
||||
self.__sha = attributes[ "sha" ]
|
||||
if "tree" in attributes and attributes[ "tree" ] is not None: # pragma no branch
|
||||
assert isinstance( attributes[ "tree" ], list ) and ( len( attributes[ "tree" ] ) == 0 or isinstance( attributes[ "tree" ][ 0 ], dict ) ), attributes[ "tree" ]
|
||||
assert all( isinstance( element, dict ) for element in attributes[ "tree" ] ), attributes[ "tree" ]
|
||||
self.__tree = [
|
||||
GitTreeElement.GitTreeElement( self.__requester, element, completion = LazyCompletion )
|
||||
for element in attributes[ "tree" ]
|
||||
|
||||
+4
-4
@@ -58,11 +58,11 @@ class Hook( object ):
|
||||
def edit( self, name, config, events = DefaultValueForOptionalParameters, add_events = DefaultValueForOptionalParameters, remove_events = DefaultValueForOptionalParameters, active = DefaultValueForOptionalParameters ):
|
||||
assert isinstance( name, ( str, unicode ) ), name
|
||||
if events is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( events, list ) and ( len( events ) == 0 or isinstance( events[ 0 ], ( str, unicode ) ) ), events
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in events ), events
|
||||
if add_events is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( add_events, list ) and ( len( add_events ) == 0 or isinstance( add_events[ 0 ], ( str, unicode ) ) ), add_events
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in add_events ), add_events
|
||||
if remove_events is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( remove_events, list ) and ( len( remove_events ) == 0 or isinstance( remove_events[ 0 ], ( str, unicode ) ) ), remove_events
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in remove_events ), remove_events
|
||||
if active is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( active, bool ), active
|
||||
post_parameters = {
|
||||
@@ -114,7 +114,7 @@ class Hook( object ):
|
||||
assert isinstance( attributes[ "created_at" ], ( str, unicode ) ), attributes[ "created_at" ]
|
||||
self.__created_at = attributes[ "created_at" ]
|
||||
if "events" in attributes and attributes[ "events" ] is not None: # pragma no branch
|
||||
assert isinstance( attributes[ "events" ], list ) and ( len( attributes[ "events" ] ) == 0 or isinstance( attributes[ "events" ][ 0 ], ( str, unicode ) ) ), attributes[ "events" ]
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in attributes[ "events" ] ), attributes[ "events" ]
|
||||
self.__events = attributes[ "events" ]
|
||||
if "id" in attributes and attributes[ "id" ] is not None: # pragma no branch
|
||||
assert isinstance( attributes[ "id" ], int ), attributes[ "id" ]
|
||||
|
||||
+4
-4
@@ -111,7 +111,7 @@ class Issue( object ):
|
||||
return self.__user
|
||||
|
||||
def add_to_labels( self, *labels ):
|
||||
assert len( labels ) == 0 or isinstance( labels[ 0 ], Label.Label ), labels
|
||||
assert all( isinstance( label, Label.Label ) for label in labels ), labels
|
||||
post_parameters = [ label._identity for label in labels ]
|
||||
status, headers, data = self.__requester.request(
|
||||
"POST",
|
||||
@@ -153,7 +153,7 @@ class Issue( object ):
|
||||
if milestone is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( milestone, int ), milestone
|
||||
if labels is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( labels, list ) and ( len( labels ) == 0 or isinstance( labels[ 0 ], ( str, unicode ) ) ), labels
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in labels ), labels
|
||||
post_parameters = dict()
|
||||
if title is not DefaultValueForOptionalParameters:
|
||||
post_parameters[ "title" ] = title
|
||||
@@ -237,7 +237,7 @@ class Issue( object ):
|
||||
)
|
||||
|
||||
def set_labels( self, *labels ):
|
||||
assert len( labels ) == 0 or isinstance( labels[ 0 ], Label.Label ), labels
|
||||
assert all( isinstance( label, Label.Label ) for label in labels ), labels
|
||||
post_parameters = [ label._identity for label in labels ]
|
||||
status, headers, data = self.__requester.request(
|
||||
"PUT",
|
||||
@@ -306,7 +306,7 @@ class Issue( object ):
|
||||
assert isinstance( attributes[ "id" ], int ), attributes[ "id" ]
|
||||
self.__id = attributes[ "id" ]
|
||||
if "labels" in attributes and attributes[ "labels" ] is not None: # pragma no branch
|
||||
assert isinstance( attributes[ "labels" ], list ) and ( len( attributes[ "labels" ] ) == 0 or isinstance( attributes[ "labels" ][ 0 ], dict ) ), attributes[ "labels" ]
|
||||
assert all( isinstance( element, dict ) for element in attributes[ "labels" ] ), attributes[ "labels" ]
|
||||
self.__labels = [
|
||||
Label.Label( self.__requester, element, completion = LazyCompletion )
|
||||
for element in attributes[ "labels" ]
|
||||
|
||||
@@ -204,7 +204,7 @@ class Organization( object ):
|
||||
def create_team( self, name, repo_names = DefaultValueForOptionalParameters, permission = DefaultValueForOptionalParameters ):
|
||||
assert isinstance( name, ( str, unicode ) ), name
|
||||
if repo_names is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( repo_names, list ) and ( len( repo_names ) == 0 or isinstance( repo_names[ 0 ], ( str, unicode ) ) ), repo_names
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in repo_names ), repo_names
|
||||
if permission is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( permission, ( str, unicode ) ), permission
|
||||
post_parameters = {
|
||||
|
||||
@@ -247,7 +247,7 @@ class Repository( object ):
|
||||
|
||||
def create_git_commit( self, message, tree, parents, author = DefaultValueForOptionalParameters, committer = DefaultValueForOptionalParameters ):
|
||||
assert isinstance( message, ( str, unicode ) ), message
|
||||
assert isinstance( parents, list ) and ( len( parents ) == 0 or isinstance( parents[ 0 ], GitCommit.GitCommit ) ), parents
|
||||
assert all( isinstance( element, GitCommit.GitCommit ) for element in parents ), parents
|
||||
post_parameters = {
|
||||
"message": message,
|
||||
"tree": tree,
|
||||
@@ -318,7 +318,7 @@ class Repository( object ):
|
||||
def create_hook( self, name, config, events = DefaultValueForOptionalParameters, active = DefaultValueForOptionalParameters ):
|
||||
assert isinstance( name, ( str, unicode ) ), name
|
||||
if events is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( events, list ) and ( len( events ) == 0 or isinstance( events[ 0 ], ( str, unicode ) ) ), events
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in events ), events
|
||||
if active is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( active, bool ), active
|
||||
post_parameters = {
|
||||
@@ -346,7 +346,7 @@ class Repository( object ):
|
||||
if milestone is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( milestone, int ), milestone
|
||||
if labels is not DefaultValueForOptionalParameters:
|
||||
assert isinstance( labels, list ) and ( len( labels ) == 0 or isinstance( labels[ 0 ], ( str, unicode ) ) ), labels
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in labels ), labels
|
||||
post_parameters = {
|
||||
"title": title,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user