@@ -57,14 +57,14 @@ def __init__(self, requester, headers, attributes, completed):
5757 self ._requester = requester
5858 # Make sure headers are signed before any operations on attributes
5959 # Object creatation requires headers as parameter
60- self ._headers = headers ;
60+ self ._headers = headers
6161 self ._initAttributes ()
6262 self ._storeAndUseAttributes (attributes )
6363
6464 # Ask requester to do some checking, for debug and test purpose
6565 # Since it's most handy to access and kinda all-knowing
66- if ( self .CHECK_AFTER_INIT_FLAG ) :
67- requester .check_me (self );
66+ if self .CHECK_AFTER_INIT_FLAG :
67+ requester .check_me (self )
6868
6969 def _storeAndUseAttributes (self , attributes ):
7070 self ._useAttributes (attributes )
@@ -100,22 +100,21 @@ def _parseDatetime(s):
100100 else :
101101 return datetime .datetime .strptime (s , "%Y-%m-%dT%H:%M:%SZ" )
102102
103- def save (self , file_name ):
103+ def save (self , file_name ): # #189: Could we use file-like objects? It would be more "pythonic" than passing filenames.
104104 '''
105105 Save instance to a file
106-
107106 :param file_name: the full path of target file
108107 '''
109-
110108 with open (file_name , 'wb' ) as f :
111- pickle .dump (self , f )
109+ pickle .dump (self , f ) # #189: This will also save self._requester, and the login/password of the user. She might not appriciate.
110+ # #189: May be better to pickle only self._rawData and self._headers and restore the object with Github.create_from_raw_data
112111
113- @classmethod
114- def load (cls , file_name ):
112+ @classmethod # #189: Could be a @staticmethod? The docstring would be simpler (no need to explain the type will be same as saved).
113+ def load (cls , file_name ): # #189: Could we use file-like objects? It would be more "pythonic" than passing filenames.
115114 '''
116115 Load saved instance from file
117116 :param file_name: the full path to saved file
118- :rtype: saved instance. The type of loaded instance remains its orginal one and will not be affected by from which derived class the method is called.
117+ :rtype: saved instance. The type of loaded instance remains its orginal one and will not be affected by from which derived class the method is called.
119118 '''
120119 with open (file_name , 'rb' ) as f :
121120 return pickle .load (f )
@@ -133,7 +132,6 @@ def last_modified(self):
133132 :type str
134133 '''
135134 return self ._headers .get (Consts .RES_LAST_MODIFED )
136-
137135
138136 def update (self ):
139137 '''
@@ -156,9 +154,10 @@ def update(self):
156154 self ._storeAndUseAttributes (data )
157155 self .__completed = True
158156 return True
159- except GithubException .NotModifiedException :
157+ except GithubException .NotModifiedException : # #189: Why raise and catch? Can't we just check?
160158 return False
161159
160+
162161class NonCompletableGithubObject (GithubObject ):
163162 def _completeIfNeeded (self ):
164163 pass
0 commit comments