Skip to content

Commit d86e44a

Browse files
committed
Resolved all pylint errors in datastore.entity.
Pylint errors were: C: 90, 0: Line too long (82/80) (line-too-long) W: 67, 4: __init__ method from base class 'dict' is not called (super-init-not-called) C:138, 4: Invalid argument name "pb" (invalid-name) E:177,43: Instance of 'Entity' has no 'to_protobuf' member (but some types could not be inferred) (maybe-no-member) E:191,19: Instance of 'Entity' has no 'to_protobuf' member (but some types could not be inferred) (maybe-no-member) E:196,27: Instance of 'Entity' has no 'is_partial' member (but some types could not be inferred) (maybe-no-member) E:202,18: Instance of 'Entity' has no 'path' member (but some types could not be inferred) (maybe-no-member) E:216,51: Instance of 'Entity' has no 'to_protobuf' member (but some types could not be inferred) (maybe-no-member) E:221,38: Instance of 'Entity' has no 'path' member (but some types could not be inferred) (maybe-no-member) R: 24, 0: Too many public methods (25/20) (too-many-public-methods) W: 18, 0: Unused import datetime (unused-import)
1 parent 20ab3b4 commit d86e44a

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

gcloud/datastore/entity.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
delete or persist the data stored on the entity.
1616
"""
1717

18-
from datetime import datetime
19-
2018
from gcloud.datastore import datastore_v1_pb2 as datastore_pb
2119
from gcloud.datastore.key import Key
2220

2321

24-
class Entity(dict):
22+
class Entity(dict): # pylint: disable=too-many-public-methods
2523
"""
2624
:type dataset: :class:`gcloud.datastore.dataset.Dataset`
2725
:param dataset: The dataset in which this entity belongs.
@@ -65,6 +63,7 @@ class Entity(dict):
6563
"""
6664

6765
def __init__(self, dataset=None, kind=None):
66+
super(Entity, self).__init__()
6867
if dataset and kind:
6968
self._key = Key(dataset=dataset).kind(kind)
7069
else:
@@ -87,7 +86,7 @@ def dataset(self):
8786
return self.key().dataset()
8887

8988
def key(self, key=None):
90-
"""Get or set the :class:`gcloud.datastore.key.Key` on the current entity.
89+
"""Get or set the Key on the current entity.
9190
9291
:type key: :class:`glcouddatastore.key.Key`
9392
:param key: The key you want to set on the entity.
@@ -100,7 +99,7 @@ def key(self, key=None):
10099
<Key[{'kind': 'OtherKeyKind', 'id': 1234}]>
101100
"""
102101

103-
if key:
102+
if key is not None:
104103
self._key = key
105104
return self
106105
else:
@@ -135,14 +134,14 @@ def from_key(cls, key):
135134
return cls().key(key)
136135

137136
@classmethod
138-
def from_protobuf(cls, pb, dataset=None):
137+
def from_protobuf(cls, pb, dataset=None): # pylint: disable=invalid-name
139138
"""Factory method for creating an entity based on a protobuf.
140139
141140
The protobuf should be one returned from the Cloud Datastore
142141
Protobuf API.
143142
144-
:type key: :class:`gcloud.datastore.datastore_v1_pb2.Entity`
145-
:param key: The Protobuf representing the entity.
143+
:type pb: :class:`gcloud.datastore.datastore_v1_pb2.Entity`
144+
:param pb: The Protobuf representing the entity.
146145
147146
:returns: The :class:`Entity` derived from the
148147
:class:`gcloud.datastore.datastore_v1_pb2.Entity`.
@@ -174,7 +173,9 @@ def reload(self):
174173
"""
175174

176175
# Note that you must have a valid key, otherwise this makes no sense.
176+
# pylint: disable=maybe-no-member
177177
entity = self.dataset().get_entity(self.key().to_protobuf())
178+
# pylint: enable=maybe-no-member
178179

179180
if entity:
180181
self.update(entity)
@@ -186,20 +187,26 @@ def save(self):
186187
:rtype: :class:`gcloud.datastore.entity.Entity`
187188
:returns: The entity with a possibly updated Key.
188189
"""
190+
# pylint: disable=maybe-no-member
189191
key_pb = self.dataset().connection().save_entity(
190192
dataset_id=self.dataset().id(),
191193
key_pb=self.key().to_protobuf(), properties=dict(self))
194+
# pylint: enable=maybe-no-member
192195

193196
# If we are in a transaction and the current entity needs an
194197
# automatically assigned ID, tell the transaction where to put that.
195198
transaction = self.dataset().connection().transaction()
199+
# pylint: disable=maybe-no-member
196200
if transaction and self.key().is_partial():
197201
transaction.add_auto_id_entity(self)
202+
# pylint: enable=maybe-no-member
198203

199204
if isinstance(key_pb, datastore_pb.Key):
200205
updated_key = Key.from_protobuf(key_pb)
201206
# Update the path (which may have been altered).
207+
# pylint: disable=maybe-no-member
202208
key = self.key().path(updated_key.path())
209+
# pylint: enable=maybe-no-member
203210
self.key(key)
204211

205212
return self
@@ -212,13 +219,20 @@ def delete(self):
212219
set on the entity. Whatever is stored remotely using the key on the
213220
entity will be deleted.
214221
"""
222+
# NOTE: pylint thinks key() is an Entity, hence key().to_protobuf()
223+
# is not defined. This is because one branch of the return
224+
# in the key() definition returns self.
225+
# pylint: disable=maybe-no-member
215226
self.dataset().connection().delete_entity(
216227
dataset_id=self.dataset().id(), key_pb=self.key().to_protobuf())
228+
# pylint: enable=maybe-no-member
217229

218230
def __repr__(self): # pragma NO COVER
219231
# An entity should have a key all the time (even if it's partial).
220232
if self.key():
233+
# pylint: disable=maybe-no-member
221234
return '<Entity%s %s>' % (self.key().path(),
222235
super(Entity, self).__repr__())
236+
# pylint: enable=maybe-no-member
223237
else:
224238
return '<Entity %s>' % (super(Entity, self).__repr__())

0 commit comments

Comments
 (0)