Skip to content

Commit aefdd22

Browse files
committed
Re-enabling redefined-builtin for Pylint.
In the process, refactoring places where builtins were used intentionally or un-intentionally.
1 parent fa39ef6 commit aefdd22

File tree

8 files changed

+38
-37
lines changed

8 files changed

+38
-37
lines changed

gcloud/bigtable/happybase/table.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def cells(self, row, column, versions=None, timestamp=None,
296296
curr_cells, include_timestamp=include_timestamp)
297297

298298
def scan(self, row_start=None, row_stop=None, row_prefix=None,
299-
columns=None, filter=None, timestamp=None,
299+
columns=None, timestamp=None,
300300
include_timestamp=False, limit=None, **kwargs):
301301
"""Create a scanner for data in this table.
302302
@@ -314,6 +314,15 @@ def scan(self, row_start=None, row_stop=None, row_prefix=None,
314314
omitted, a full table scan is done. Note that this usually results
315315
in severe performance problems.
316316
317+
The keyword argument ``filter`` is also supported (beyond column and
318+
row range filters supported here). HappyBase / HBase users will have
319+
used this as an HBase filter string. (See the `Thrift docs`_ for more
320+
details on those filters.) However, Google Cloud Bigtable doesn't
321+
support those filter strings so a
322+
:class:`~gcloud.bigtable.row.RowFilter` should be used instead.
323+
324+
.. _Thrift docs: http://hbase.apache.org/0.94/book/thrift.html
325+
317326
The arguments ``batch_size``, ``scan_batching`` and ``sorted_columns``
318327
are allowed (as keyword arguments) for compatibility with
319328
HappyBase. However, they will not be used in any way, and will cause a
@@ -348,13 +357,6 @@ def scan(self, row_start=None, row_stop=None, row_prefix=None,
348357
* an entire column family: ``fam`` or ``fam:``
349358
* a single column: ``fam:col``
350359
351-
:type filter: :class:`RowFilter <gcloud.bigtable.row.RowFilter>`
352-
:param filter: (Optional) An additional filter (beyond column and
353-
row range filters supported here). HappyBase / HBase
354-
users will have used this as an HBase filter string. See
355-
http://hbase.apache.org/0.94/book/thrift.html
356-
for more details on those filters.
357-
358360
:type timestamp: int
359361
:param timestamp: (Optional) Timestamp (in milliseconds since the
360362
epoch). If specified, only cells returned before (or
@@ -376,6 +378,7 @@ def scan(self, row_start=None, row_stop=None, row_prefix=None,
376378
:class:`TypeError <exceptions.TypeError>` if a string
377379
``filter`` is used.
378380
"""
381+
filter_ = kwargs.pop('filter', None)
379382
legacy_args = []
380383
for kw_name in ('batch_size', 'scan_batching', 'sorted_columns'):
381384
if kw_name in kwargs:
@@ -399,22 +402,22 @@ def scan(self, row_start=None, row_stop=None, row_prefix=None,
399402
row_stop = _string_successor(row_prefix)
400403

401404
filters = []
402-
if isinstance(filter, six.string_types):
405+
if isinstance(filter_, six.string_types):
403406
raise TypeError('Specifying filters as a string is not supported '
404407
'by Cloud Bigtable. Use a '
405408
'gcloud.bigtable.row.RowFilter instead.')
406-
elif filter is not None:
407-
filters.append(filter)
409+
elif filter_ is not None:
410+
filters.append(filter_)
408411

409412
if columns is not None:
410413
filters.append(_columns_filter_helper(columns))
411414
# versions == 1 since we only want the latest.
412-
filter_ = _filter_chain_helper(versions=1, timestamp=timestamp,
413-
filters=filters)
415+
filter_chain = _filter_chain_helper(versions=1, timestamp=timestamp,
416+
filters=filters)
414417

415418
partial_rows_data = self._low_level_table.read_rows(
416419
start_key=row_start, end_key=row_stop,
417-
limit=limit, filter_=filter_)
420+
limit=limit, filter_=filter_chain)
418421

419422
# Mutable copy of data.
420423
rows_dict = partial_rows_data.rows

gcloud/datastore/test_batch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,14 @@ def test_as_context_mgr_w_error(self):
298298

299299
class _PathElementPB(object):
300300

301-
def __init__(self, id):
302-
self.id = id
301+
def __init__(self, id_):
302+
self.id = id_
303303

304304

305305
class _KeyPB(object):
306306

307-
def __init__(self, id):
308-
self.path = [_PathElementPB(id)]
307+
def __init__(self, id_):
308+
self.path = [_PathElementPB(id_)]
309309

310310

311311
class _Connection(object):

gcloud/datastore/test_connection.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ def _getTargetClass(self):
2222

2323
return Connection
2424

25-
def _make_key_pb(self, project, id=1234):
25+
def _make_key_pb(self, project, id_=1234):
2626
from gcloud.datastore.key import Key
2727
path_args = ('Kind',)
28-
if id is not None:
29-
path_args += (id,)
28+
if id_ is not None:
29+
path_args += (id_,)
3030
return Key(*path_args, project=project).to_protobuf()
3131

3232
def _make_query_pb(self, kind):
@@ -362,7 +362,7 @@ def test_lookup_multiple_keys_empty_response(self):
362362

363363
PROJECT = 'PROJECT'
364364
key_pb1 = self._make_key_pb(PROJECT)
365-
key_pb2 = self._make_key_pb(PROJECT, id=2345)
365+
key_pb2 = self._make_key_pb(PROJECT, id_=2345)
366366
rsp_pb = datastore_pb2.LookupResponse()
367367
conn = self._makeOne()
368368
URI = '/'.join([
@@ -391,7 +391,7 @@ def test_lookup_multiple_keys_w_missing(self):
391391

392392
PROJECT = 'PROJECT'
393393
key_pb1 = self._make_key_pb(PROJECT)
394-
key_pb2 = self._make_key_pb(PROJECT, id=2345)
394+
key_pb2 = self._make_key_pb(PROJECT, id_=2345)
395395
rsp_pb = datastore_pb2.LookupResponse()
396396
er_1 = rsp_pb.missing.add()
397397
er_1.entity.key.CopyFrom(key_pb1)
@@ -425,7 +425,7 @@ def test_lookup_multiple_keys_w_deferred(self):
425425

426426
PROJECT = 'PROJECT'
427427
key_pb1 = self._make_key_pb(PROJECT)
428-
key_pb2 = self._make_key_pb(PROJECT, id=2345)
428+
key_pb2 = self._make_key_pb(PROJECT, id_=2345)
429429
rsp_pb = datastore_pb2.LookupResponse()
430430
rsp_pb.deferred.add().CopyFrom(key_pb1)
431431
rsp_pb.deferred.add().CopyFrom(key_pb2)
@@ -778,12 +778,12 @@ def test_allocate_ids_non_empty(self):
778778

779779
PROJECT = 'PROJECT'
780780
before_key_pbs = [
781-
self._make_key_pb(PROJECT, id=None),
782-
self._make_key_pb(PROJECT, id=None),
781+
self._make_key_pb(PROJECT, id_=None),
782+
self._make_key_pb(PROJECT, id_=None),
783783
]
784784
after_key_pbs = [
785785
self._make_key_pb(PROJECT),
786-
self._make_key_pb(PROJECT, id=2345),
786+
self._make_key_pb(PROJECT, id_=2345),
787787
]
788788
rsp_pb = datastore_pb2.AllocateIdsResponse()
789789
rsp_pb.keys.add().CopyFrom(after_key_pbs[0])

gcloud/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class InternalServerError(ServerError):
147147
code = 500
148148

149149

150-
class NotImplemented(ServerError):
150+
class MethodNotImplemented(ServerError):
151151
"""Exception mapping a '501 Not Implemented' response."""
152152
code = 501
153153

gcloud/search/document.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ def _parse_value_resource(resource):
204204
return TimestampValue(value)
205205
if 'geoValue' in resource:
206206
lat_long = resource['geoValue']
207-
lat, long = [float(coord.strip()) for coord in lat_long.split(',')]
208-
return GeoValue((lat, long))
207+
latitude, longitude = [float(coord.strip())
208+
for coord in lat_long.split(',')]
209+
return GeoValue((latitude, longitude))
209210
raise ValueError("Unknown value type")
210211

211212
def _parse_fields_resource(self, resource):

scripts/pylintrc_default

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ load-plugins=pylint.extensions.check_docs
6868
# - maybe-no-member: bi-modal functions confuse pylint type inference.
6969
# - no-member: indirections in protobuf-generated code
7070
# - protected-access: helpers use '_foo' of classes from generated code.
71-
# - redefined-builtin: use of 'id', 'type', 'filter' args in API-bound funcs;
72-
# use of 'NotImplemented' to map HTTP response code.
7371
# - similarities: 'Bucket' and 'Blob' define 'metageneration' and 'owner' with
7472
# identical implementation but different docstrings.
7573
# - star-args: standard Python idioms for varargs:
@@ -93,7 +91,6 @@ disable =
9391
maybe-no-member,
9492
no-member,
9593
protected-access,
96-
redefined-builtin,
9794
similarities,
9895
star-args,
9996
redefined-variable-type,

system_tests/clear_datastore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import os
2020

21-
from six.moves import input
21+
import six
2222

2323
from gcloud import datastore
2424
from gcloud.environment_vars import TESTS_PROJECT
@@ -99,7 +99,7 @@ def remove_all_entities(client=None):
9999
print_func('This command will remove all entities for '
100100
'the following kinds:')
101101
print_func('\n'.join(['- ' + val for val in ALL_KINDS]))
102-
response = input('Is this OK [y/n]? ')
102+
response = six.moves.input('Is this OK [y/n]? ')
103103
if response.lower() == 'y':
104104
remove_all_entities()
105105
else:

system_tests/populate_datastore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import os
2121

22-
from six.moves import zip
22+
import six
2323

2424
from gcloud import datastore
2525
from gcloud.environment_vars import TESTS_PROJECT
@@ -93,7 +93,7 @@ def add_characters(client=None):
9393
# Get a client that uses the test dataset.
9494
client = datastore.Client(project=os.getenv(TESTS_PROJECT))
9595
with client.transaction() as xact:
96-
for key_path, character in zip(KEY_PATHS, CHARACTERS):
96+
for key_path, character in six.moves.zip(KEY_PATHS, CHARACTERS):
9797
if key_path[-1] != character['name']:
9898
raise ValueError(('Character and key don\'t agree',
9999
key_path, character))

0 commit comments

Comments
 (0)