19
19
from gcloud .datastore .key import Key
20
20
21
21
22
- class Entity (dict ): # pylint: disable=too-many-public-methods
22
+ class Entity (dict ):
23
23
""":type dataset: :class:`gcloud.datastore.dataset.Dataset`
24
24
:param dataset: The dataset in which this entity belongs.
25
25
@@ -91,7 +91,9 @@ def key(self, key=None):
91
91
:type key: :class:`glcouddatastore.key.Key`
92
92
:param key: The key you want to set on the entity.
93
93
94
- :returns: Either the current key or the :class:`Entity`.
94
+ :rtype: :class:`gcloud.datastore.key.Key` or :class:`Entity`.
95
+ :returns: Either the current key (on get) or the current
96
+ object (on set).
95
97
96
98
>>> entity.key(my_other_key) # This returns the original entity.
97
99
<Entity[{'kind': 'OtherKeyKind', 'id': 1234}] {'property': 'value'}>
@@ -137,7 +139,7 @@ def from_key(cls, key):
137
139
return cls ().key (key )
138
140
139
141
@classmethod
140
- def from_protobuf (cls , pb , dataset = None ): # pylint: disable=invalid-name
142
+ def from_protobuf (cls , pb , dataset = None ):
141
143
"""Factory method for creating an entity based on a protobuf.
142
144
143
145
The protobuf should be one returned from the Cloud Datastore
@@ -176,9 +178,7 @@ def reload(self):
176
178
"""
177
179
178
180
# Note that you must have a valid key, otherwise this makes no sense.
179
- # pylint: disable=maybe-no-member
180
181
entity = self .dataset ().get_entity (self .key ().to_protobuf ())
181
- # pylint: enable=maybe-no-member
182
182
183
183
if entity :
184
184
self .update (entity )
@@ -190,26 +190,20 @@ def save(self):
190
190
:rtype: :class:`gcloud.datastore.entity.Entity`
191
191
:returns: The entity with a possibly updated Key.
192
192
"""
193
- # pylint: disable=maybe-no-member
194
193
key_pb = self .dataset ().connection ().save_entity (
195
194
dataset_id = self .dataset ().id (),
196
195
key_pb = self .key ().to_protobuf (), properties = dict (self ))
197
- # pylint: enable=maybe-no-member
198
196
199
197
# If we are in a transaction and the current entity needs an
200
198
# automatically assigned ID, tell the transaction where to put that.
201
199
transaction = self .dataset ().connection ().transaction ()
202
- # pylint: disable=maybe-no-member
203
200
if transaction and self .key ().is_partial ():
204
201
transaction .add_auto_id_entity (self )
205
- # pylint: enable=maybe-no-member
206
202
207
203
if isinstance (key_pb , datastore_pb .Key ):
208
204
updated_key = Key .from_protobuf (key_pb )
209
205
# Update the path (which may have been altered).
210
- # pylint: disable=maybe-no-member
211
206
key = self .key ().path (updated_key .path ())
212
- # pylint: enable=maybe-no-member
213
207
self .key (key )
214
208
215
209
return self
@@ -222,20 +216,13 @@ def delete(self):
222
216
set on the entity. Whatever is stored remotely using the key on the
223
217
entity will be deleted.
224
218
"""
225
- # NOTE: pylint thinks key() is an Entity, hence key().to_protobuf()
226
- # is not defined. This is because one branch of the return
227
- # in the key() definition returns self.
228
- # pylint: disable=maybe-no-member
229
219
self .dataset ().connection ().delete_entity (
230
220
dataset_id = self .dataset ().id (), key_pb = self .key ().to_protobuf ())
231
- # pylint: enable=maybe-no-member
232
221
233
222
def __repr__ (self ):
234
223
# An entity should have a key all the time (even if it's partial).
235
224
if self .key ():
236
- # pylint: disable=maybe-no-member
237
225
return '<Entity%s %s>' % (self .key ().path (),
238
226
super (Entity , self ).__repr__ ())
239
- # pylint: enable=maybe-no-member
240
227
else :
241
228
return '<Entity %s>' % (super (Entity , self ).__repr__ ())
0 commit comments