Skip to content

Commit 86b308a

Browse files
committed
Merge pull request #238 from dhermes/large-style-changes
Large number of style-related changes to pass pylint
2 parents 83e8262 + d609071 commit 86b308a

34 files changed

+858
-624
lines changed

gcloud/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
"""GCloud API access in idiomatic Python."""
2+
3+
24
__version__ = '0.02.2'

gcloud/connection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" Shared implementation of connections to API servers."""
2+
23
from pkg_resources import get_distribution
34

45
import httplib2
@@ -28,6 +29,7 @@ def __init__(self, credentials=None):
2829
:type credentials: :class:`oauth2client.client.OAuth2Credentials`
2930
:param credentials: The OAuth2 Credentials to use for this connection.
3031
"""
32+
self._http = None
3133
self._credentials = credentials
3234

3335
@property
@@ -45,7 +47,7 @@ def http(self):
4547
:rtype: :class:`httplib2.Http`
4648
:returns: A Http object used to transport data.
4749
"""
48-
if not hasattr(self, '_http'):
50+
if self._http is None:
4951
self._http = httplib2.Http()
5052
if self._credentials:
5153
self._http = self._credentials.authorize(self._http)

gcloud/datastore/_helpers.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
These functions are *not* part of the API.
44
"""
55
import calendar
6-
from datetime import datetime, timedelta
6+
import datetime
77

88
from google.protobuf.internal.type_checkers import Int64ValueChecker
99
import pytz
@@ -43,7 +43,7 @@ def _get_protobuf_attribute_and_value(val):
4343
:returns: A tuple of the attribute name and proper value type.
4444
"""
4545

46-
if isinstance(val, datetime):
46+
if isinstance(val, datetime.datetime):
4747
name = 'timestamp_microseconds'
4848
# If the datetime is naive (no timezone), consider that it was
4949
# intended to be UTC and replace the tzinfo to that effect.
@@ -91,8 +91,8 @@ def _get_value_from_value_pb(value_pb):
9191
result = None
9292
if value_pb.HasField('timestamp_microseconds_value'):
9393
microseconds = value_pb.timestamp_microseconds_value
94-
naive = (datetime.utcfromtimestamp(0) +
95-
timedelta(microseconds=microseconds))
94+
naive = (datetime.datetime.utcfromtimestamp(0) +
95+
datetime.timedelta(microseconds=microseconds))
9696
result = naive.replace(tzinfo=pytz.utc)
9797

9898
elif value_pb.HasField('key_value'):
@@ -163,9 +163,9 @@ def _set_protobuf_value(value_pb, val):
163163
key = val.key()
164164
if key is not None:
165165
e_pb.key.CopyFrom(key.to_protobuf())
166-
for k, v in val.items():
166+
for item_key, value in val.iteritems():
167167
p_pb = e_pb.property.add()
168-
p_pb.name = k
169-
_set_protobuf_value(p_pb.value, v)
168+
p_pb.name = item_key
169+
_set_protobuf_value(p_pb.value, value)
170170
else: # scalar, just assign
171171
setattr(value_pb, attr, val)

gcloud/datastore/connection.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Connections to gcloud datastore API servers."""
2+
23
from gcloud import connection
34
from gcloud.datastore import datastore_v1_pb2 as datastore_pb
45
from gcloud.datastore import _helpers
@@ -23,7 +24,7 @@ class Connection(connection.Connection):
2324
"""A template for the URL of a particular API call."""
2425

2526
def __init__(self, credentials=None):
26-
self._credentials = credentials
27+
super(Connection, self).__init__(credentials=credentials)
2728
self._current_transaction = None
2829

2930
def _request(self, dataset_id, method, data):
@@ -240,11 +241,12 @@ def run_query(self, dataset_id, query_pb, namespace=None):
240241
request.query.CopyFrom(query_pb)
241242
response = self._rpc(dataset_id, 'runQuery', request,
242243
datastore_pb.RunQueryResponse)
243-
return ([e.entity for e in response.batch.entity_result],
244-
response.batch.end_cursor,
245-
response.batch.more_results,
246-
response.batch.skipped_results,
247-
)
244+
return (
245+
[e.entity for e in response.batch.entity_result],
246+
response.batch.end_cursor,
247+
response.batch.more_results,
248+
response.batch.skipped_results,
249+
)
248250

249251
def lookup(self, dataset_id, key_pbs):
250252
"""Lookup keys from a dataset in the Cloud Datastore.

gcloud/datastore/dataset.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def query(self, *args, **kwargs):
7070
:rtype: :class:`gcloud.datastore.query.Query`
7171
:returns: a new Query instance, bound to this dataset.
7272
"""
73+
# This import is here to avoid circular references.
7374
from gcloud.datastore.query import Query
7475
kwargs['dataset'] = self
7576
return Query(*args, **kwargs)
@@ -83,6 +84,7 @@ def entity(self, kind):
8384
:rtype: :class:`gcloud.datastore.entity.Entity`
8485
:returns: a new Entity instance, bound to this dataset.
8586
"""
87+
# This import is here to avoid circular references.
8688
from gcloud.datastore.entity import Entity
8789
return Entity(dataset=self, kind=kind)
8890

@@ -96,6 +98,7 @@ def transaction(self, *args, **kwargs):
9698
:rtype: :class:`gcloud.datastore.transaction.Transaction`
9799
:returns: a new Transaction instance, bound to this dataset.
98100
"""
101+
# This import is here to avoid circular references.
99102
from gcloud.datastore.transaction import Transaction
100103
kwargs['dataset'] = self
101104
return Transaction(*args, **kwargs)

gcloud/datastore/entity.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class NoKey(RuntimeError):
2323
"""Exception raised by Entity methods which require a key."""
2424

2525

26-
class Entity(dict): # pylint: disable=too-many-public-methods
26+
class Entity(dict):
2727
""":type dataset: :class:`gcloud.datastore.dataset.Dataset`
2828
:param dataset: The dataset in which this entity belongs.
2929
@@ -95,7 +95,9 @@ def key(self, key=None):
9595
:type key: :class:`glcouddatastore.key.Key`
9696
:param key: The key you want to set on the entity.
9797
98-
:returns: Either the current key or the :class:`Entity`.
98+
:rtype: :class:`gcloud.datastore.key.Key` or :class:`Entity`.
99+
:returns: Either the current key (on get) or the current
100+
object (on set).
99101
100102
>>> entity.key(my_other_key) # This returns the original entity.
101103
<Entity[{'kind': 'OtherKeyKind', 'id': 1234}] {'property': 'value'}>
@@ -141,7 +143,7 @@ def from_key(cls, key):
141143
return cls().key(key)
142144

143145
@classmethod
144-
def from_protobuf(cls, pb, dataset=None): # pylint: disable=invalid-name
146+
def from_protobuf(cls, pb, dataset=None):
145147
"""Factory method for creating an entity based on a protobuf.
146148
147149
The protobuf should be one returned from the Cloud Datastore

gcloud/datastore/key.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def is_partial(self):
159159
:returns: True if the last element of the key's path does not have
160160
an 'id' or a 'name'.
161161
"""
162-
return (self.id_or_name() is None)
162+
return self.id_or_name() is None
163163

164164
def dataset(self, dataset=None):
165165
"""Dataset setter / getter.
@@ -231,19 +231,19 @@ def kind(self, kind=None):
231231
elif self.path():
232232
return self._path[-1]['kind']
233233

234-
def id(self, id=None):
234+
def id(self, id_to_set=None):
235235
"""ID setter / getter. Based on the last element of path.
236236
237-
:type kind: :class:`str`
238-
:param kind: The new kind for the key.
237+
:type id_to_set: :class:`int`
238+
:param id_to_set: The new ID for the key.
239239
240240
:rtype: :class:`Key` (for setter); or :class:`int` (for getter)
241241
:returns: a new key, cloned from self., with the given id (setter);
242-
or self's id (getter).
242+
or self's id (getter).
243243
"""
244-
if id:
244+
if id_to_set:
245245
clone = self._clone()
246-
clone._path[-1]['id'] = id
246+
clone._path[-1]['id'] = id_to_set
247247
return clone
248248
elif self.path():
249249
return self._path[-1].get('id')

gcloud/datastore/query.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,9 @@ def fetch(self, limit=None):
315315
if limit:
316316
clone = self.limit(limit)
317317

318-
(entity_pbs,
319-
end_cursor,
320-
more_results,
321-
skipped_results) = self.dataset().connection().run_query(
318+
query_results = self.dataset().connection().run_query(
322319
query_pb=clone.to_protobuf(), dataset_id=self.dataset().id())
320+
entity_pbs, end_cursor = query_results[:2]
323321

324322
self._cursor = end_cursor
325323
return [Entity.from_protobuf(entity, dataset=self.dataset())
@@ -379,14 +377,14 @@ def order(self, *properties):
379377
"""
380378
clone = self._clone()
381379

382-
for p in properties:
380+
for prop in properties:
383381
property_order = clone._pb.order.add()
384382

385-
if p.startswith('-'):
386-
property_order.property.name = p[1:]
383+
if prop.startswith('-'):
384+
property_order.property.name = prop[1:]
387385
property_order.direction = property_order.DESCENDING
388386
else:
389-
property_order.property.name = p
387+
property_order.property.name = prop
390388
property_order.direction = property_order.ASCENDING
391389

392390
return clone

gcloud/datastore/test___init__.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ def test_it(self):
2525
found = self._callFUT(CLIENT_EMAIL, f.name)
2626
self.assertTrue(isinstance(found, Connection))
2727
self.assertTrue(found._credentials is client._signed)
28-
self.assertEqual(client._called_with,
29-
{'service_account_name': CLIENT_EMAIL,
30-
'private_key': PRIVATE_KEY,
31-
'scope': SCOPE,
32-
})
28+
expected_called_with = {
29+
'service_account_name': CLIENT_EMAIL,
30+
'private_key': PRIVATE_KEY,
31+
'scope': SCOPE,
32+
}
33+
self.assertEqual(client._called_with, expected_called_with)
3334

3435

3536
class Test_get_dataset(unittest2.TestCase):
@@ -59,8 +60,9 @@ def test_it(self):
5960
self.assertTrue(isinstance(found, Dataset))
6061
self.assertTrue(isinstance(found.connection(), Connection))
6162
self.assertEqual(found.id(), DATASET_ID)
62-
self.assertEqual(client._called_with,
63-
{'service_account_name': CLIENT_EMAIL,
64-
'private_key': PRIVATE_KEY,
65-
'scope': SCOPE,
66-
})
63+
expected_called_with = {
64+
'service_account_name': CLIENT_EMAIL,
65+
'private_key': PRIVATE_KEY,
66+
'scope': SCOPE,
67+
}
68+
self.assertEqual(client._called_with, expected_called_with)

gcloud/datastore/test__helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_unknown(self):
182182
from gcloud.datastore.datastore_v1_pb2 import Value
183183

184184
pb = Value()
185-
self.assertEqual(self._callFUT(pb), None) # XXX desirable?
185+
self.assertEqual(self._callFUT(pb), None)
186186

187187

188188
class Test__get_value_from_property_pb(unittest2.TestCase):

0 commit comments

Comments
 (0)