From 71a5e9751dab22817ee45325ed033677d29d2d9b Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Thu, 31 May 2012 18:27:54 +0100 Subject: [PATCH] Refactor assertions about parameters --- .../GithubObject.MethodBody.CheckArguments.py | 20 ++-- src/github/AuthenticatedUser.py | 60 ++++-------- src/github/Authorization.py | 15 +-- src/github/Commit.py | 9 +- src/github/Gist.py | 3 +- src/github/GitRef.py | 3 +- src/github/Hook.py | 12 +-- src/github/Issue.py | 18 ++-- src/github/Milestone.py | 9 +- src/github/NamedUser.py | 6 +- src/github/Organization.py | 48 ++++------ src/github/PullRequest.py | 12 +-- src/github/Repository.py | 96 +++++++------------ src/github/RepositoryKey.py | 6 +- src/github/Team.py | 3 +- src/github/UserKey.py | 6 +- 16 files changed, 110 insertions(+), 216 deletions(-) diff --git a/codegen/templates/GithubObject.MethodBody.CheckArguments.py b/codegen/templates/GithubObject.MethodBody.CheckArguments.py index c35e9cc7..40c63e2e 100644 --- a/codegen/templates/GithubObject.MethodBody.CheckArguments.py +++ b/codegen/templates/GithubObject.MethodBody.CheckArguments.py @@ -34,40 +34,36 @@ {% endif %} {% endfor %} {% for parameter in method.optionalParameters %} - {% if parameter.type.name != "@todo" %} - if {{ parameter.name }} is not GithubObject.NotSet: - {% endif %} - {% if parameter.type.cardinality == "scalar" %} {% if parameter.type.simple %} {% if parameter.type.name == "string" %} - assert isinstance( {{ parameter.name }}, ( str, unicode ) ), {{ parameter.name }} + assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, ( str, unicode ) ), {{ parameter.name }} {% endif %} {% if parameter.type.name == "integer" %} - assert isinstance( {{ parameter.name }}, int ), {{ parameter.name }} + assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, int ), {{ parameter.name }} {% endif %} {% if parameter.type.name == "bool" %} - assert isinstance( {{ parameter.name }}, bool ), {{ parameter.name }} + assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, bool ), {{ parameter.name }} {% endif %} {% else %} - assert isinstance( {{ parameter.name }}, {{ parameter.type.name }}.{{ parameter.type.name }} ), {{ parameter.name }} + assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, {{ parameter.type.name }}.{{ parameter.type.name }} ), {{ parameter.name }} {% endif %} {% else %} {% if parameter.type.simple %} {% if parameter.type.name == "string" %} - assert all( isinstance( element, ( str, unicode ) ) for element in {{ parameter.name }} ), {{ parameter.name }} + assert {{ parameter.name }} is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in {{ parameter.name }} ), {{ parameter.name }} {% endif %} {% if parameter.type.name == "integer" %} - assert all( isinstance( element, int ) for element in {{ parameter.name }} ), {{ parameter.name }} + assert {{ parameter.name }} is GithubObject.NotSet or all( isinstance( element, int ) for element in {{ parameter.name }} ), {{ parameter.name }} {% endif %} {% if parameter.type.name == "bool" %} - assert all( isinstance( element, bool ) for element in {{ parameter.name }} ), {{ parameter.name }} + assert {{ parameter.name }} is GithubObject.NotSet or all( isinstance( element, bool ) for element in {{ parameter.name }} ), {{ parameter.name }} {% endif %} {% else %} - assert all( isinstance( element, {{ parameter.type.name }}.{{ parameter.type.name }} ) for element in {{ parameter.name }} ), {{ parameter.name }} + assert {{ parameter.name }} is GithubObject.NotSet or all( isinstance( element, {{ parameter.type.name }}.{{ parameter.type.name }} ) for element in {{ parameter.name }} ), {{ parameter.name }} {% endif %} {% endif %} diff --git a/src/github/AuthenticatedUser.py b/src/github/AuthenticatedUser.py index b84b1cf8..4395e8d8 100644 --- a/src/github/AuthenticatedUser.py +++ b/src/github/AuthenticatedUser.py @@ -172,12 +172,9 @@ class AuthenticatedUser( GithubObject.GithubObject ): self._checkStatus( status, data ) def create_authorization( self, scopes = GithubObject.NotSet, note = GithubObject.NotSet, note_url = GithubObject.NotSet ): - if scopes is not GithubObject.NotSet: - assert all( isinstance( element, ( str, unicode ) ) for element in scopes ), scopes - if note is not GithubObject.NotSet: - assert isinstance( note, ( str, unicode ) ), note - if note_url is not GithubObject.NotSet: - assert isinstance( note_url, ( str, unicode ) ), note_url + assert scopes is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in scopes ), scopes + assert note is GithubObject.NotSet or isinstance( note, ( str, unicode ) ), note + assert note_url is GithubObject.NotSet or isinstance( note_url, ( str, unicode ) ), note_url post_parameters = dict() if scopes is not GithubObject.NotSet: post_parameters[ "scopes" ] = scopes @@ -207,8 +204,7 @@ class AuthenticatedUser( GithubObject.GithubObject ): def create_gist( self, public, files, description = GithubObject.NotSet ): assert isinstance( public, bool ), public - if description is not GithubObject.NotSet: - assert isinstance( description, ( str, unicode ) ), description + assert description is GithubObject.NotSet or isinstance( description, ( str, unicode ) ), description post_parameters = { "public": public, "files": files, @@ -242,18 +238,12 @@ class AuthenticatedUser( GithubObject.GithubObject ): def create_repo( self, name, description = GithubObject.NotSet, homepage = GithubObject.NotSet, private = GithubObject.NotSet, has_issues = GithubObject.NotSet, has_wiki = GithubObject.NotSet, has_downloads = GithubObject.NotSet ): assert isinstance( name, ( str, unicode ) ), name - if description is not GithubObject.NotSet: - assert isinstance( description, ( str, unicode ) ), description - if homepage is not GithubObject.NotSet: - assert isinstance( homepage, ( str, unicode ) ), homepage - if private is not GithubObject.NotSet: - assert isinstance( private, bool ), private - if has_issues is not GithubObject.NotSet: - assert isinstance( has_issues, bool ), has_issues - if has_wiki is not GithubObject.NotSet: - assert isinstance( has_wiki, bool ), has_wiki - if has_downloads is not GithubObject.NotSet: - assert isinstance( has_downloads, bool ), has_downloads + assert description is GithubObject.NotSet or isinstance( description, ( str, unicode ) ), description + assert homepage is GithubObject.NotSet or isinstance( homepage, ( str, unicode ) ), homepage + assert private is GithubObject.NotSet or isinstance( private, bool ), private + assert has_issues is GithubObject.NotSet or isinstance( has_issues, bool ), has_issues + assert has_wiki is GithubObject.NotSet or isinstance( has_wiki, bool ), has_wiki + assert has_downloads is GithubObject.NotSet or isinstance( has_downloads, bool ), has_downloads post_parameters = { "name": name, } @@ -279,20 +269,13 @@ class AuthenticatedUser( GithubObject.GithubObject ): return Repository.Repository( self._requester, data, completed = True ) def edit( self, name = GithubObject.NotSet, email = GithubObject.NotSet, blog = GithubObject.NotSet, company = GithubObject.NotSet, location = GithubObject.NotSet, hireable = GithubObject.NotSet, bio = GithubObject.NotSet ): - if name is not GithubObject.NotSet: - assert isinstance( name, ( str, unicode ) ), name - if email is not GithubObject.NotSet: - assert isinstance( email, ( str, unicode ) ), email - if blog is not GithubObject.NotSet: - assert isinstance( blog, ( str, unicode ) ), blog - if company is not GithubObject.NotSet: - assert isinstance( company, ( str, unicode ) ), company - if location is not GithubObject.NotSet: - assert isinstance( location, ( str, unicode ) ), location - if hireable is not GithubObject.NotSet: - assert isinstance( hireable, bool ), hireable - if bio is not GithubObject.NotSet: - assert isinstance( bio, ( str, unicode ) ), bio + assert name is GithubObject.NotSet or isinstance( name, ( str, unicode ) ), name + assert email is GithubObject.NotSet or isinstance( email, ( str, unicode ) ), email + assert blog is GithubObject.NotSet or isinstance( blog, ( str, unicode ) ), blog + assert company is GithubObject.NotSet or isinstance( company, ( str, unicode ) ), company + assert location is GithubObject.NotSet or isinstance( location, ( str, unicode ) ), location + assert hireable is GithubObject.NotSet or isinstance( hireable, bool ), hireable + assert bio is GithubObject.NotSet or isinstance( bio, ( str, unicode ) ), bio post_parameters = dict() if name is not GithubObject.NotSet: post_parameters[ "name" ] = name @@ -497,12 +480,9 @@ class AuthenticatedUser( GithubObject.GithubObject ): return Repository.Repository( self._requester, data, completed = True ) def get_repos( self, type = GithubObject.NotSet, sort = GithubObject.NotSet, direction = GithubObject.NotSet ): - if type is not GithubObject.NotSet: - assert isinstance( type, ( str, unicode ) ), type - if sort is not GithubObject.NotSet: - assert isinstance( sort, ( str, unicode ) ), sort - if direction is not GithubObject.NotSet: - assert isinstance( direction, ( str, unicode ) ), direction + assert type is GithubObject.NotSet or isinstance( type, ( str, unicode ) ), type + assert sort is GithubObject.NotSet or isinstance( sort, ( str, unicode ) ), sort + assert direction is GithubObject.NotSet or isinstance( direction, ( str, unicode ) ), direction url_parameters = dict() if type is not GithubObject.NotSet: url_parameters[ "type" ] = type diff --git a/src/github/Authorization.py b/src/github/Authorization.py index c656f308..cb1b4aa4 100644 --- a/src/github/Authorization.py +++ b/src/github/Authorization.py @@ -61,16 +61,11 @@ class Authorization( GithubObject.GithubObject ): self._checkStatus( status, data ) def edit( self, scopes = GithubObject.NotSet, add_scopes = GithubObject.NotSet, remove_scopes = GithubObject.NotSet, note = GithubObject.NotSet, note_url = GithubObject.NotSet ): - if scopes is not GithubObject.NotSet: - assert all( isinstance( element, ( str, unicode ) ) for element in scopes ), scopes - if add_scopes is not GithubObject.NotSet: - assert all( isinstance( element, ( str, unicode ) ) for element in add_scopes ), add_scopes - if remove_scopes is not GithubObject.NotSet: - assert all( isinstance( element, ( str, unicode ) ) for element in remove_scopes ), remove_scopes - if note is not GithubObject.NotSet: - assert isinstance( note, ( str, unicode ) ), note - if note_url is not GithubObject.NotSet: - assert isinstance( note_url, ( str, unicode ) ), note_url + assert scopes is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in scopes ), scopes + assert add_scopes is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in add_scopes ), add_scopes + assert remove_scopes is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in remove_scopes ), remove_scopes + assert note is GithubObject.NotSet or isinstance( note, ( str, unicode ) ), note + assert note_url is GithubObject.NotSet or isinstance( note_url, ( str, unicode ) ), note_url post_parameters = dict() if scopes is not GithubObject.NotSet: post_parameters[ "scopes" ] = scopes diff --git a/src/github/Commit.py b/src/github/Commit.py index ebc19242..92784dd5 100644 --- a/src/github/Commit.py +++ b/src/github/Commit.py @@ -54,12 +54,9 @@ class Commit( GithubObject.GithubObject ): def create_comment( self, body, line = GithubObject.NotSet, path = GithubObject.NotSet, position = GithubObject.NotSet ): assert isinstance( body, ( str, unicode ) ), body - if line is not GithubObject.NotSet: - assert isinstance( line, int ), line - if path is not GithubObject.NotSet: - assert isinstance( path, ( str, unicode ) ), path - if position is not GithubObject.NotSet: - assert isinstance( position, int ), position + assert line is GithubObject.NotSet or isinstance( line, int ), line + assert path is GithubObject.NotSet or isinstance( path, ( str, unicode ) ), path + assert position is GithubObject.NotSet or isinstance( position, int ), position post_parameters = { "body": body, } diff --git a/src/github/Gist.py b/src/github/Gist.py index 07fe4e9f..51f90e59 100644 --- a/src/github/Gist.py +++ b/src/github/Gist.py @@ -119,8 +119,7 @@ class Gist( GithubObject.GithubObject ): self._checkStatus( status, data ) def edit( self, description = GithubObject.NotSet, files = GithubObject.NotSet ): - if description is not GithubObject.NotSet: - assert isinstance( description, ( str, unicode ) ), description + assert description is GithubObject.NotSet or isinstance( description, ( str, unicode ) ), description post_parameters = dict() if description is not GithubObject.NotSet: post_parameters[ "description" ] = description diff --git a/src/github/GitRef.py b/src/github/GitRef.py index f12d6dab..994e383d 100644 --- a/src/github/GitRef.py +++ b/src/github/GitRef.py @@ -32,8 +32,7 @@ class GitRef( GithubObject.GithubObject ): def edit( self, sha, force = GithubObject.NotSet ): assert isinstance( sha, ( str, unicode ) ), sha - if force is not GithubObject.NotSet: - assert isinstance( force, bool ), force + assert force is GithubObject.NotSet or isinstance( force, bool ), force post_parameters = { "sha": sha, } diff --git a/src/github/Hook.py b/src/github/Hook.py index f8e971b3..fb8bf97b 100644 --- a/src/github/Hook.py +++ b/src/github/Hook.py @@ -62,14 +62,10 @@ class Hook( GithubObject.GithubObject ): def edit( self, name, config, events = GithubObject.NotSet, add_events = GithubObject.NotSet, remove_events = GithubObject.NotSet, active = GithubObject.NotSet ): assert isinstance( name, ( str, unicode ) ), name - if events is not GithubObject.NotSet: - assert all( isinstance( element, ( str, unicode ) ) for element in events ), events - if add_events is not GithubObject.NotSet: - assert all( isinstance( element, ( str, unicode ) ) for element in add_events ), add_events - if remove_events is not GithubObject.NotSet: - assert all( isinstance( element, ( str, unicode ) ) for element in remove_events ), remove_events - if active is not GithubObject.NotSet: - assert isinstance( active, bool ), active + assert events is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in events ), events + assert add_events is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in add_events ), add_events + assert remove_events is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in remove_events ), remove_events + assert active is GithubObject.NotSet or isinstance( active, bool ), active post_parameters = { "name": name, "config": config, diff --git a/src/github/Issue.py b/src/github/Issue.py index 82ba3885..40fc673f 100644 --- a/src/github/Issue.py +++ b/src/github/Issue.py @@ -138,18 +138,12 @@ class Issue( GithubObject.GithubObject ): self._checkStatus( status, data ) def edit( self, title = GithubObject.NotSet, body = GithubObject.NotSet, assignee = GithubObject.NotSet, state = GithubObject.NotSet, milestone = GithubObject.NotSet, labels = GithubObject.NotSet ): - if title is not GithubObject.NotSet: - assert isinstance( title, ( str, unicode ) ), title - if body is not GithubObject.NotSet: - assert isinstance( body, ( str, unicode ) ), body - if assignee is not GithubObject.NotSet: - assert isinstance( assignee, ( str, unicode ) ), assignee - if state is not GithubObject.NotSet: - assert isinstance( state, ( str, unicode ) ), state - if milestone is not GithubObject.NotSet: - assert isinstance( milestone, int ), milestone - if labels is not GithubObject.NotSet: - assert all( isinstance( element, ( str, unicode ) ) for element in labels ), labels + assert title is GithubObject.NotSet or isinstance( title, ( str, unicode ) ), title + assert body is GithubObject.NotSet or isinstance( body, ( str, unicode ) ), body + assert assignee is GithubObject.NotSet or isinstance( assignee, ( str, unicode ) ), assignee + assert state is GithubObject.NotSet or isinstance( state, ( str, unicode ) ), state + assert milestone is GithubObject.NotSet or isinstance( milestone, int ), milestone + assert labels is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in labels ), labels post_parameters = dict() if title is not GithubObject.NotSet: post_parameters[ "title" ] = title diff --git a/src/github/Milestone.py b/src/github/Milestone.py index 0504baa1..4e747605 100644 --- a/src/github/Milestone.py +++ b/src/github/Milestone.py @@ -74,12 +74,9 @@ class Milestone( GithubObject.GithubObject ): def edit( self, title, state = GithubObject.NotSet, description = GithubObject.NotSet, due_on = GithubObject.NotSet ): assert isinstance( title, ( str, unicode ) ), title - if state is not GithubObject.NotSet: - assert isinstance( state, ( str, unicode ) ), state - if description is not GithubObject.NotSet: - assert isinstance( description, ( str, unicode ) ), description - if due_on is not GithubObject.NotSet: - assert isinstance( due_on, ( str, unicode ) ), due_on + assert state is GithubObject.NotSet or isinstance( state, ( str, unicode ) ), state + assert description is GithubObject.NotSet or isinstance( description, ( str, unicode ) ), description + assert due_on is GithubObject.NotSet or isinstance( due_on, ( str, unicode ) ), due_on post_parameters = { "title": title, } diff --git a/src/github/NamedUser.py b/src/github/NamedUser.py index 266e98c5..dd295b8f 100644 --- a/src/github/NamedUser.py +++ b/src/github/NamedUser.py @@ -144,8 +144,7 @@ class NamedUser( GithubObject.GithubObject ): def create_gist( self, public, files, description = GithubObject.NotSet ): assert isinstance( public, bool ), public - if description is not GithubObject.NotSet: - assert isinstance( description, ( str, unicode ) ), description + assert description is GithubObject.NotSet or isinstance( description, ( str, unicode ) ), description post_parameters = { "public": public, "files": files, @@ -293,8 +292,7 @@ class NamedUser( GithubObject.GithubObject ): return Repository.Repository( self._requester, data, completed = True ) def get_repos( self, type = GithubObject.NotSet ): - if type is not GithubObject.NotSet: - assert isinstance( type, ( str, unicode ) ), type + assert type is GithubObject.NotSet or isinstance( type, ( str, unicode ) ), type url_parameters = dict() if type is not GithubObject.NotSet: url_parameters[ "type" ] = type diff --git a/src/github/Organization.py b/src/github/Organization.py index 8d177674..294633e7 100644 --- a/src/github/Organization.py +++ b/src/github/Organization.py @@ -157,20 +157,13 @@ class Organization( GithubObject.GithubObject ): def create_repo( self, name, description = GithubObject.NotSet, homepage = GithubObject.NotSet, private = GithubObject.NotSet, has_issues = GithubObject.NotSet, has_wiki = GithubObject.NotSet, has_downloads = GithubObject.NotSet, team_id = GithubObject.NotSet ): assert isinstance( name, ( str, unicode ) ), name - if description is not GithubObject.NotSet: - assert isinstance( description, ( str, unicode ) ), description - if homepage is not GithubObject.NotSet: - assert isinstance( homepage, ( str, unicode ) ), homepage - if private is not GithubObject.NotSet: - assert isinstance( private, bool ), private - if has_issues is not GithubObject.NotSet: - assert isinstance( has_issues, bool ), has_issues - if has_wiki is not GithubObject.NotSet: - assert isinstance( has_wiki, bool ), has_wiki - if has_downloads is not GithubObject.NotSet: - assert isinstance( has_downloads, bool ), has_downloads - if team_id is not GithubObject.NotSet: - assert isinstance( team_id, int ), team_id + assert description is GithubObject.NotSet or isinstance( description, ( str, unicode ) ), description + assert homepage is GithubObject.NotSet or isinstance( homepage, ( str, unicode ) ), homepage + assert private is GithubObject.NotSet or isinstance( private, bool ), private + assert has_issues is GithubObject.NotSet or isinstance( has_issues, bool ), has_issues + assert has_wiki is GithubObject.NotSet or isinstance( has_wiki, bool ), has_wiki + assert has_downloads is GithubObject.NotSet or isinstance( has_downloads, bool ), has_downloads + assert team_id is GithubObject.NotSet or isinstance( team_id, int ), team_id post_parameters = { "name": name, } @@ -199,10 +192,8 @@ class Organization( GithubObject.GithubObject ): def create_team( self, name, repo_names = GithubObject.NotSet, permission = GithubObject.NotSet ): assert isinstance( name, ( str, unicode ) ), name - if repo_names is not GithubObject.NotSet: - assert all( isinstance( element, ( str, unicode ) ) for element in repo_names ), repo_names - if permission is not GithubObject.NotSet: - assert isinstance( permission, ( str, unicode ) ), permission + assert repo_names is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in repo_names ), repo_names + assert permission is GithubObject.NotSet or isinstance( permission, ( str, unicode ) ), permission post_parameters = { "name": name, } @@ -220,18 +211,12 @@ class Organization( GithubObject.GithubObject ): return Team.Team( self._requester, data, completed = True ) def edit( self, billing_email = GithubObject.NotSet, blog = GithubObject.NotSet, company = GithubObject.NotSet, email = GithubObject.NotSet, location = GithubObject.NotSet, name = GithubObject.NotSet ): - if billing_email is not GithubObject.NotSet: - assert isinstance( billing_email, ( str, unicode ) ), billing_email - if blog is not GithubObject.NotSet: - assert isinstance( blog, ( str, unicode ) ), blog - if company is not GithubObject.NotSet: - assert isinstance( company, ( str, unicode ) ), company - if email is not GithubObject.NotSet: - assert isinstance( email, ( str, unicode ) ), email - if location is not GithubObject.NotSet: - assert isinstance( location, ( str, unicode ) ), location - if name is not GithubObject.NotSet: - assert isinstance( name, ( str, unicode ) ), name + assert billing_email is GithubObject.NotSet or isinstance( billing_email, ( str, unicode ) ), billing_email + assert blog is GithubObject.NotSet or isinstance( blog, ( str, unicode ) ), blog + assert company is GithubObject.NotSet or isinstance( company, ( str, unicode ) ), company + assert email is GithubObject.NotSet or isinstance( email, ( str, unicode ) ), email + assert location is GithubObject.NotSet or isinstance( location, ( str, unicode ) ), location + assert name is GithubObject.NotSet or isinstance( name, ( str, unicode ) ), name post_parameters = dict() if billing_email is not GithubObject.NotSet: post_parameters[ "billing_email" ] = billing_email @@ -311,8 +296,7 @@ class Organization( GithubObject.GithubObject ): return Repository.Repository( self._requester, data, completed = True ) def get_repos( self, type = GithubObject.NotSet ): - if type is not GithubObject.NotSet: - assert isinstance( type, ( str, unicode ) ), type + assert type is GithubObject.NotSet or isinstance( type, ( str, unicode ) ), type url_parameters = dict() if type is not GithubObject.NotSet: url_parameters[ "type" ] = type diff --git a/src/github/PullRequest.py b/src/github/PullRequest.py index 9e132c00..4ba50b98 100644 --- a/src/github/PullRequest.py +++ b/src/github/PullRequest.py @@ -162,12 +162,9 @@ class PullRequest( GithubObject.GithubObject ): return PullRequestComment.PullRequestComment( self._requester, data, completed = True ) def edit( self, title = GithubObject.NotSet, body = GithubObject.NotSet, state = GithubObject.NotSet ): - if title is not GithubObject.NotSet: - assert isinstance( title, ( str, unicode ) ), title - if body is not GithubObject.NotSet: - assert isinstance( body, ( str, unicode ) ), body - if state is not GithubObject.NotSet: - assert isinstance( state, ( str, unicode ) ), state + assert title is GithubObject.NotSet or isinstance( title, ( str, unicode ) ), title + assert body is GithubObject.NotSet or isinstance( body, ( str, unicode ) ), body + assert state is GithubObject.NotSet or isinstance( state, ( str, unicode ) ), state post_parameters = dict() if title is not GithubObject.NotSet: post_parameters[ "title" ] = title @@ -250,8 +247,7 @@ class PullRequest( GithubObject.GithubObject ): return status == 204 def merge( self, commit_message = GithubObject.NotSet ): - if commit_message is not GithubObject.NotSet: - assert isinstance( commit_message, ( str, unicode ) ), commit_message + assert commit_message is GithubObject.NotSet or isinstance( commit_message, ( str, unicode ) ), commit_message post_parameters = dict() if commit_message is not GithubObject.NotSet: post_parameters[ "commit_message" ] = commit_message diff --git a/src/github/Repository.py b/src/github/Repository.py index b3c442ec..e6bf9629 100644 --- a/src/github/Repository.py +++ b/src/github/Repository.py @@ -206,10 +206,8 @@ class Repository( GithubObject.GithubObject ): def create_download( self, name, size, description = GithubObject.NotSet, content_type = GithubObject.NotSet ): assert isinstance( name, ( str, unicode ) ), name assert isinstance( size, int ), size - if description is not GithubObject.NotSet: - assert isinstance( description, ( str, unicode ) ), description - if content_type is not GithubObject.NotSet: - assert isinstance( content_type, ( str, unicode ) ), content_type + assert description is GithubObject.NotSet or isinstance( description, ( str, unicode ) ), description + assert content_type is GithubObject.NotSet or isinstance( content_type, ( str, unicode ) ), content_type post_parameters = { "name": name, "size": size, @@ -319,10 +317,8 @@ class Repository( GithubObject.GithubObject ): def create_hook( self, name, config, events = GithubObject.NotSet, active = GithubObject.NotSet ): assert isinstance( name, ( str, unicode ) ), name - if events is not GithubObject.NotSet: - assert all( isinstance( element, ( str, unicode ) ) for element in events ), events - if active is not GithubObject.NotSet: - assert isinstance( active, bool ), active + assert events is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in events ), events + assert active is GithubObject.NotSet or isinstance( active, bool ), active post_parameters = { "name": name, "config": config, @@ -342,14 +338,10 @@ class Repository( GithubObject.GithubObject ): def create_issue( self, title, body = GithubObject.NotSet, assignee = GithubObject.NotSet, milestone = GithubObject.NotSet, labels = GithubObject.NotSet ): assert isinstance( title, ( str, unicode ) ), title - if body is not GithubObject.NotSet: - assert isinstance( body, ( str, unicode ) ), body - if assignee is not GithubObject.NotSet: - assert isinstance( assignee, ( str, unicode ) ), assignee - if milestone is not GithubObject.NotSet: - assert isinstance( milestone, int ), milestone - if labels is not GithubObject.NotSet: - assert all( isinstance( element, ( str, unicode ) ) for element in labels ), labels + assert body is GithubObject.NotSet or isinstance( body, ( str, unicode ) ), body + assert assignee is GithubObject.NotSet or isinstance( assignee, ( str, unicode ) ), assignee + assert milestone is GithubObject.NotSet or isinstance( milestone, int ), milestone + assert labels is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in labels ), labels post_parameters = { "title": title, } @@ -404,12 +396,9 @@ class Repository( GithubObject.GithubObject ): def create_milestone( self, title, state = GithubObject.NotSet, description = GithubObject.NotSet, due_on = GithubObject.NotSet ): assert isinstance( title, ( str, unicode ) ), title - if state is not GithubObject.NotSet: - assert isinstance( state, ( str, unicode ) ), state - if description is not GithubObject.NotSet: - assert isinstance( description, ( str, unicode ) ), description - if due_on is not GithubObject.NotSet: - assert isinstance( due_on, ( str, unicode ) ), due_on + assert state is GithubObject.NotSet or isinstance( state, ( str, unicode ) ), state + assert description is GithubObject.NotSet or isinstance( description, ( str, unicode ) ), description + assert due_on is GithubObject.NotSet or isinstance( due_on, ( str, unicode ) ), due_on post_parameters = { "title": title, } @@ -456,18 +445,12 @@ class Repository( GithubObject.GithubObject ): def edit( self, name, description = GithubObject.NotSet, homepage = GithubObject.NotSet, public = GithubObject.NotSet, has_issues = GithubObject.NotSet, has_wiki = GithubObject.NotSet, has_downloads = GithubObject.NotSet ): assert isinstance( name, ( str, unicode ) ), name - if description is not GithubObject.NotSet: - assert isinstance( description, ( str, unicode ) ), description - if homepage is not GithubObject.NotSet: - assert isinstance( homepage, ( str, unicode ) ), homepage - if public is not GithubObject.NotSet: - assert isinstance( public, bool ), public - if has_issues is not GithubObject.NotSet: - assert isinstance( has_issues, bool ), has_issues - if has_wiki is not GithubObject.NotSet: - assert isinstance( has_wiki, bool ), has_wiki - if has_downloads is not GithubObject.NotSet: - assert isinstance( has_downloads, bool ), has_downloads + assert description is GithubObject.NotSet or isinstance( description, ( str, unicode ) ), description + assert homepage is GithubObject.NotSet or isinstance( homepage, ( str, unicode ) ), homepage + assert public is GithubObject.NotSet or isinstance( public, bool ), public + assert has_issues is GithubObject.NotSet or isinstance( has_issues, bool ), has_issues + assert has_wiki is GithubObject.NotSet or isinstance( has_wiki, bool ), has_wiki + assert has_downloads is GithubObject.NotSet or isinstance( has_downloads, bool ), has_downloads post_parameters = { "name": name, } @@ -560,10 +543,8 @@ class Repository( GithubObject.GithubObject ): return Commit.Commit( self._requester, data, completed = True ) def get_commits( self, sha = GithubObject.NotSet, path = GithubObject.NotSet ): - if sha is not GithubObject.NotSet: - assert isinstance( sha, ( str, unicode ) ), sha - if path is not GithubObject.NotSet: - assert isinstance( path, ( str, unicode ) ), path + assert sha is GithubObject.NotSet or isinstance( sha, ( str, unicode ) ), sha + assert path is GithubObject.NotSet or isinstance( path, ( str, unicode ) ), path url_parameters = dict() if sha is not GithubObject.NotSet: url_parameters[ "sha" ] = sha @@ -715,8 +696,7 @@ class Repository( GithubObject.GithubObject ): def get_git_tree( self, sha, recursive = GithubObject.NotSet ): assert isinstance( sha, ( str, unicode ) ), sha - if recursive is not GithubObject.NotSet: - assert isinstance( recursive, bool ), recursive + assert recursive is GithubObject.NotSet or isinstance( recursive, bool ), recursive url_parameters = dict() if recursive is not GithubObject.NotSet: url_parameters[ "recursive" ] = recursive @@ -767,22 +747,14 @@ class Repository( GithubObject.GithubObject ): return Issue.Issue( self._requester, data, completed = True ) def get_issues( self, milestone = GithubObject.NotSet, state = GithubObject.NotSet, assignee = GithubObject.NotSet, mentioned = GithubObject.NotSet, labels = GithubObject.NotSet, sort = GithubObject.NotSet, direction = GithubObject.NotSet, since = GithubObject.NotSet ): - if milestone is not GithubObject.NotSet: - assert isinstance( milestone, int ), milestone - if state is not GithubObject.NotSet: - assert isinstance( state, ( str, unicode ) ), state - if assignee is not GithubObject.NotSet: - assert isinstance( assignee, ( str, unicode ) ), assignee - if mentioned is not GithubObject.NotSet: - assert isinstance( mentioned, ( str, unicode ) ), mentioned - if labels is not GithubObject.NotSet: - assert isinstance( labels, ( str, unicode ) ), labels - if sort is not GithubObject.NotSet: - assert isinstance( sort, ( str, unicode ) ), sort - if direction is not GithubObject.NotSet: - assert isinstance( direction, ( str, unicode ) ), direction - if since is not GithubObject.NotSet: - assert isinstance( since, ( str, unicode ) ), since + assert milestone is GithubObject.NotSet or isinstance( milestone, int ), milestone + assert state is GithubObject.NotSet or isinstance( state, ( str, unicode ) ), state + assert assignee is GithubObject.NotSet or isinstance( assignee, ( str, unicode ) ), assignee + assert mentioned is GithubObject.NotSet or isinstance( mentioned, ( str, unicode ) ), mentioned + assert labels is GithubObject.NotSet or isinstance( labels, ( str, unicode ) ), labels + assert sort is GithubObject.NotSet or isinstance( sort, ( str, unicode ) ), sort + assert direction is GithubObject.NotSet or isinstance( direction, ( str, unicode ) ), direction + assert since is GithubObject.NotSet or isinstance( since, ( str, unicode ) ), since url_parameters = dict() if milestone is not GithubObject.NotSet: url_parameters[ "milestone" ] = milestone @@ -914,12 +886,9 @@ class Repository( GithubObject.GithubObject ): return Milestone.Milestone( self._requester, data, completed = True ) def get_milestones( self, state = GithubObject.NotSet, sort = GithubObject.NotSet, direction = GithubObject.NotSet ): - if state is not GithubObject.NotSet: - assert isinstance( state, ( str, unicode ) ), state - if sort is not GithubObject.NotSet: - assert isinstance( sort, ( str, unicode ) ), sort - if direction is not GithubObject.NotSet: - assert isinstance( direction, ( str, unicode ) ), direction + assert state is GithubObject.NotSet or isinstance( state, ( str, unicode ) ), state + assert sort is GithubObject.NotSet or isinstance( sort, ( str, unicode ) ), sort + assert direction is GithubObject.NotSet or isinstance( direction, ( str, unicode ) ), direction url_parameters = dict() if state is not GithubObject.NotSet: url_parameters[ "state" ] = state @@ -968,8 +937,7 @@ class Repository( GithubObject.GithubObject ): return PullRequest.PullRequest( self._requester, data, completed = True ) def get_pulls( self, state = GithubObject.NotSet ): - if state is not GithubObject.NotSet: - assert isinstance( state, ( str, unicode ) ), state + assert state is GithubObject.NotSet or isinstance( state, ( str, unicode ) ), state url_parameters = dict() if state is not GithubObject.NotSet: url_parameters[ "state" ] = state diff --git a/src/github/RepositoryKey.py b/src/github/RepositoryKey.py index 8e0dfe6c..2e6610d4 100644 --- a/src/github/RepositoryKey.py +++ b/src/github/RepositoryKey.py @@ -47,10 +47,8 @@ class RepositoryKey( GithubObject.GithubObject ): self._checkStatus( status, data ) def edit( self, title = GithubObject.NotSet, key = GithubObject.NotSet ): - if title is not GithubObject.NotSet: - assert isinstance( title, ( str, unicode ) ), title - if key is not GithubObject.NotSet: - assert isinstance( key, ( str, unicode ) ), key + assert title is GithubObject.NotSet or isinstance( title, ( str, unicode ) ), title + assert key is GithubObject.NotSet or isinstance( key, ( str, unicode ) ), key post_parameters = dict() if title is not GithubObject.NotSet: post_parameters[ "title" ] = title diff --git a/src/github/Team.py b/src/github/Team.py index 3aa3c269..51a99e55 100644 --- a/src/github/Team.py +++ b/src/github/Team.py @@ -69,8 +69,7 @@ class Team( GithubObject.GithubObject ): def edit( self, name, permission = GithubObject.NotSet ): assert isinstance( name, ( str, unicode ) ), name - if permission is not GithubObject.NotSet: - assert isinstance( permission, ( str, unicode ) ), permission + assert permission is GithubObject.NotSet or isinstance( permission, ( str, unicode ) ), permission post_parameters = { "name": name, } diff --git a/src/github/UserKey.py b/src/github/UserKey.py index 35711ef6..44b84da4 100644 --- a/src/github/UserKey.py +++ b/src/github/UserKey.py @@ -39,10 +39,8 @@ class UserKey( GithubObject.GithubObject ): self._checkStatus( status, data ) def edit( self, title = GithubObject.NotSet, key = GithubObject.NotSet ): - if title is not GithubObject.NotSet: - assert isinstance( title, ( str, unicode ) ), title - if key is not GithubObject.NotSet: - assert isinstance( key, ( str, unicode ) ), key + assert title is GithubObject.NotSet or isinstance( title, ( str, unicode ) ), title + assert key is GithubObject.NotSet or isinstance( key, ( str, unicode ) ), key post_parameters = dict() if title is not GithubObject.NotSet: post_parameters[ "title" ] = title