Skip to content

Commit 3073d32

Browse files
committed
Updated source for Pylint 1.5.
Pylint 1.5 brought with it much more than pylint.extensions.check_docs The changes for this PR are - checking import order - checking self._foo is set in __init__ - complaining about methods that don't use self - complaining about not calling super().__init__ (for the virtual base class we used) - complaining about not (self == other) in __ne__, suggested (self != other) instead - complaining about unit tests checking None result from methods which are known (by static analysis?) to return None - complaining about not over-riding virtual method in storage _PropertyMixin - aggressively checking `redefined-variable-type` when variables can be optionally float/int/Entity/Key/etc. - checking that GCloudError constructor is called correctly in unit tests - checking that subclass method overrides use the same arguments (this occurred in BigQuery test_job with _makeResource)
1 parent bc181db commit 3073d32

File tree

20 files changed

+77
-52
lines changed

20 files changed

+77
-52
lines changed

gcloud/_helpers.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,20 @@
1919
import calendar
2020
import datetime
2121
import os
22-
import six
22+
from threading import local as Local
2323
import socket
2424

25-
try:
26-
from threading import local as Local
27-
except ImportError: # pragma: NO COVER (who doesn't have it?)
28-
class Local(object):
29-
"""Placeholder for non-threaded applications."""
30-
25+
import six
3126
from six.moves.http_client import HTTPConnection # pylint: disable=F0401
3227

28+
from gcloud.environment_vars import PROJECT
29+
30+
# pylint: disable=wrong-import-position
3331
try:
3432
from google.appengine.api import app_identity
3533
except ImportError:
3634
app_identity = None
37-
38-
from gcloud.environment_vars import PROJECT
35+
# pylint: enable=wrong-import-position
3936

4037

4138
_NOW = datetime.datetime.utcnow # To be replaced by tests.
@@ -297,7 +294,7 @@ def _to_bytes(value, encoding='ascii'):
297294

298295

299296
try:
300-
from pytz import UTC # pylint: disable=unused-import
297+
from pytz import UTC # pylint: disable=unused-import,wrong-import-position
301298
except ImportError:
302299
UTC = _UTC() # Singleton instance to be used throughout.
303300

gcloud/bigquery/dataset.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ class Dataset(object):
6060
:param access_grants: roles granted to entities for this dataset
6161
"""
6262

63+
_access_grants = None
64+
6365
def __init__(self, name, client, access_grants=()):
6466
self.name = name
6567
self._client = client
6668
self._properties = {}
69+
# Let the @property do validation.
6770
self.access_grants = access_grants
6871

6972
@property
@@ -283,7 +286,8 @@ def _require_client(self, client):
283286
client = self._client
284287
return client
285288

286-
def _parse_access_grants(self, access):
289+
@staticmethod
290+
def _parse_access_grants(access):
287291
"""Parse a resource fragment into a set of access grants.
288292
289293
:type access: list of mappings

gcloud/bigquery/job.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,14 @@ class LoadTableFromStorageJob(_AsyncJob):
444444
:type schema: list of :class:`gcloud.bigquery.table.SchemaField`
445445
:param schema: The job's schema
446446
"""
447+
448+
_schema = None
449+
447450
def __init__(self, name, destination, source_uris, client, schema=()):
448451
super(LoadTableFromStorageJob, self).__init__(name, client)
449452
self.destination = destination
450453
self.source_uris = source_uris
454+
# Let the @property do validation.
451455
self.schema = schema
452456
self._configuration = _LoadConfiguration()
453457

gcloud/bigquery/table.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,13 @@ class Table(object):
7272
:param schema: The table's schema
7373
"""
7474

75+
_schema = None
76+
7577
def __init__(self, name, dataset, schema=()):
7678
self.name = name
7779
self._dataset = dataset
7880
self._properties = {}
81+
# Let the @property do validation.
7982
self.schema = schema
8083

8184
@property

gcloud/client.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ class _ClientFactoryMixin(object):
3131
This class is virtual.
3232
"""
3333

34-
def __init__(self, *args, **kwargs):
35-
raise NotImplementedError('_ClientFactoryMixin is a virtual class')
36-
3734
@classmethod
3835
def from_service_account_json(cls, json_credentials_path, *args, **kwargs):
3936
"""Factory to retrieve JSON credentials while creating client.

gcloud/credentials.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,22 @@
2626
from oauth2client.client import _get_application_default_credential_from_file
2727
from oauth2client import crypt
2828
from oauth2client import service_account
29-
30-
try:
31-
from google.appengine.api import app_identity
32-
except ImportError:
33-
app_identity = None
34-
3529
try:
3630
from oauth2client.appengine import AppAssertionCredentials as _GAECreds
3731
except ImportError:
3832
class _GAECreds(object):
3933
"""Dummy class if not in App Engine environment."""
4034

35+
# pylint: disable=wrong-import-position
36+
try:
37+
from google.appengine.api import app_identity
38+
except ImportError:
39+
app_identity = None
40+
4141
from gcloud._helpers import UTC
4242
from gcloud._helpers import _NOW
4343
from gcloud._helpers import _microseconds_from_datetime
44+
# pylint: enable=wrong-import-position
4445

4546

4647
def get_credentials():

gcloud/datastore/entity.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ def __ne__(self, other):
106106
:rtype: boolean
107107
:returns: False if the entities compare equal, else True.
108108
"""
109-
return not self == other
109+
eq_val = self.__eq__(other)
110+
if eq_val is NotImplemented:
111+
return True
112+
else:
113+
return not eq_val
110114

111115
@property
112116
def kind(self):

gcloud/datastore/key.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ def __ne__(self, other):
9999
:rtype: boolean
100100
:returns: False if the keys compare equal, else True.
101101
"""
102-
return not self == other
102+
eq_val = self.__eq__(other)
103+
if eq_val is NotImplemented:
104+
return True
105+
else:
106+
return not eq_val
103107

104108
def __hash__(self):
105109
"""Hash a keys for use in a dictionary lookp.

gcloud/datastore/test_client.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,7 @@ def test_put_multi_no_batch_w_partial_key(self):
620620
client = self._makeOne(credentials=creds)
621621
client.connection._commit.append(_CommitResult(key))
622622

623-
result = client.put_multi([entity])
624-
self.assertTrue(result is None)
623+
client.put_multi([entity])
625624

626625
self.assertEqual(len(client.connection._commit_cw), 1)
627626
dataset_id, mutation, transaction_id = client.connection._commit_cw[0]
@@ -644,9 +643,8 @@ def test_put_multi_existing_batch_w_completed_key(self):
644643
key = entity.key = _Key(self.DATASET_ID)
645644

646645
with _NoCommitBatch(client) as CURR_BATCH:
647-
result = client.put_multi([entity])
646+
client.put_multi([entity])
648647

649-
self.assertEqual(result, None)
650648
self.assertEqual(len(CURR_BATCH.mutation.insert_auto_id), 0)
651649
upserts = list(CURR_BATCH.mutation.upsert)
652650
self.assertEqual(len(upserts), 1)
@@ -675,8 +673,8 @@ def _delete_multi(*args, **kw):
675673
def test_delete_multi_no_keys(self):
676674
creds = object()
677675
client = self._makeOne(credentials=creds)
678-
result = client.delete_multi([])
679-
self.assertEqual(result, None)
676+
client.delete_multi([])
677+
self.assertEqual(len(client.connection._commit_cw), 0)
680678

681679
def test_delete_multi_no_batch(self):
682680
from gcloud.datastore.test_batch import _CommitResult
@@ -688,8 +686,7 @@ def test_delete_multi_no_batch(self):
688686
client = self._makeOne(credentials=creds)
689687
client.connection._commit.append(_CommitResult())
690688

691-
result = client.delete_multi([key])
692-
self.assertEqual(result, None)
689+
client.delete_multi([key])
693690
self.assertEqual(len(client.connection._commit_cw), 1)
694691
dataset_id, mutation, transaction_id = client.connection._commit_cw[0]
695692
self.assertEqual(dataset_id, self.DATASET_ID)
@@ -704,9 +701,8 @@ def test_delete_multi_w_existing_batch(self):
704701
key = _Key(self.DATASET_ID)
705702

706703
with _NoCommitBatch(client) as CURR_BATCH:
707-
result = client.delete_multi([key])
704+
client.delete_multi([key])
708705

709-
self.assertEqual(result, None)
710706
self.assertEqual(len(CURR_BATCH.mutation.insert_auto_id), 0)
711707
self.assertEqual(len(CURR_BATCH.mutation.upsert), 0)
712708
deletes = list(CURR_BATCH.mutation.delete)
@@ -722,9 +718,8 @@ def test_delete_multi_w_existing_transaction(self):
722718
key = _Key(self.DATASET_ID)
723719

724720
with _NoCommitTransaction(client) as CURR_XACT:
725-
result = client.delete_multi([key])
721+
client.delete_multi([key])
726722

727-
self.assertEqual(result, None)
728723
self.assertEqual(len(CURR_XACT.mutation.insert_auto_id), 0)
729724
self.assertEqual(len(CURR_XACT.mutation.upsert), 0)
730725
deletes = list(CURR_XACT.mutation.delete)

gcloud/search/document.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ def from_api_repr(cls, resource, index):
182182
document._parse_fields_resource(resource)
183183
return document
184184

185-
def _parse_value_resource(self, resource):
185+
@staticmethod
186+
def _parse_value_resource(resource):
186187
"""Helper for _parse_fields_resource"""
187188
if 'stringValue' in resource:
188189
string_format = resource.get('stringFormat')
@@ -245,7 +246,8 @@ def _require_client(self, client):
245246
client = self.index._client
246247
return client
247248

248-
def _build_value_resource(self, value):
249+
@staticmethod
250+
def _build_value_resource(value):
249251
"""Helper for _build_fields_resource"""
250252
result = {}
251253
if value.value_type == 'string':

0 commit comments

Comments
 (0)