Skip to content

Commit 506a304

Browse files
author
Jon Wayne Parrott
authored
Fix pylint for the main package (#3658)
1 parent 768d667 commit 506a304

File tree

12 files changed

+31
-17
lines changed

12 files changed

+31
-17
lines changed

core/.flake8

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[flake8]
2+
import-order-style=google
23
exclude =
34
__pycache__,
45
.git,

core/google/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""Google namespace package."""
16+
1517
try:
1618
import pkg_resources
1719
pkg_resources.declare_namespace(__name__)

core/google/cloud/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""Google Cloud namespace package."""
16+
1517
try:
1618
import pkg_resources
1719
pkg_resources.declare_namespace(__name__)

core/google/cloud/_helpers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
This module is not part of the public API surface.
1818
"""
1919

20-
# Avoid the grpc and google.cloud.grpc collision.
2120
from __future__ import absolute_import
2221

2322
import calendar
@@ -104,7 +103,7 @@ def top(self):
104103
:rtype: object
105104
:returns: the top-most item, or None if the stack is empty.
106105
"""
107-
if len(self._stack) > 0:
106+
if self._stack:
108107
return self._stack[-1]
109108

110109

core/google/cloud/_http.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ def api_request(self, method, path, query_params=None,
279279
can allow custom behavior, for example, to defer an HTTP request
280280
and complete initialization of the object at a later time.
281281
282-
:raises: Exception if the response code is not 200 OK.
282+
:raises ~google.cloud.exceptions.GoogleCloudError: if the response code
283+
is not 200 OK.
284+
:raises TypeError: if the response content type is not JSON.
283285
:rtype: dict or str
284286
:returns: The API response payload, either as a raw string or
285287
a dictionary if the response is valid JSON.

core/google/cloud/_testing.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@
1414

1515
"""Shared testing utilities."""
1616

17-
18-
# Avoid the grpc and google.cloud.grpc collision.
1917
from __future__ import absolute_import
2018

2119

2220
class _Monkey(object):
23-
# context-manager for replacing module names in the scope of a test.
21+
"""Context-manager for replacing module names in the scope of a test."""
2422

2523
def __init__(self, module, **kw):
2624
self.module = module
27-
if len(kw) == 0: # pragma: NO COVER
25+
if not kw: # pragma: NO COVER
2826
raise ValueError('_Monkey was used with nothing to monkey-patch')
2927
self.to_restore = {key: getattr(module, key) for key in kw}
3028
for key, value in kw.items():
@@ -68,8 +66,12 @@ def _tempdir_mgr():
6866
return _tempdir_mgr
6967

7068

69+
# pylint: disable=invalid-name
70+
# Retain _tempdir as a constant for backwards compatibility despite
71+
# being an invalid name.
7172
_tempdir = _tempdir_maker()
7273
del _tempdir_maker
74+
# pylint: enable=invalid-name
7375

7476

7577
class _GAXBaseAPI(object):
@@ -79,7 +81,8 @@ class _GAXBaseAPI(object):
7981
def __init__(self, **kw):
8082
self.__dict__.update(kw)
8183

82-
def _make_grpc_error(self, status_code, trailing=None):
84+
@staticmethod
85+
def _make_grpc_error(status_code, trailing=None):
8386
from grpc._channel import _RPCState
8487
from google.cloud.exceptions import GrpcRendezvous
8588

@@ -111,6 +114,7 @@ def __init__(self, *pages, **kwargs):
111114
self.page_token = kwargs.get('page_token')
112115

113116
def next(self):
117+
"""Iterate to the next page."""
114118
import six
115119
return six.next(self._pages)
116120

core/google/cloud/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def from_service_account_json(cls, json_credentials_path, *args, **kwargs):
6464
6565
:rtype: :class:`_ClientFactoryMixin`
6666
:returns: The client created with the retrieved JSON credentials.
67-
:raises: :class:`TypeError` if there is a conflict with the kwargs
67+
:raises TypeError: if there is a conflict with the kwargs
6868
and the credentials created by the factory.
6969
"""
7070
if 'credentials' in kwargs:

core/google/cloud/future/operation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Operation(base.PollingFuture):
3434
initial operation.
3535
refresh (Callable[[], Operation]): A callable that returns the
3636
latest state of the operation.
37-
cancel (Callable[[], None]), A callable that tries to cancel
37+
cancel (Callable[[], None]): A callable that tries to cancel
3838
the operation.
3939
result_type (type): The protobuf type for the operation's result.
4040
metadata_type (type): The protobuf type for the operation's

core/google/cloud/iam.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,14 @@ def to_api_repr(self):
226226
if self.version is not None:
227227
resource['version'] = self.version
228228

229-
if len(self._bindings) > 0:
229+
if self._bindings:
230230
bindings = resource['bindings'] = []
231231
for role, members in sorted(self._bindings.items()):
232-
if len(members) > 0:
232+
if members:
233233
bindings.append(
234234
{'role': role, 'members': sorted(set(members))})
235235

236-
if len(bindings) == 0:
236+
if not bindings:
237237
del resource['bindings']
238238

239239
return resource

core/google/cloud/iterator.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ def _page_iter(self, increment):
242242
results per page while an items iterator will want
243243
to increment per item.
244244
245-
Yields :class:`Page` instances.
245+
:rtype: :class:`Page`
246+
:returns: pages
246247
"""
247248
page = self._next_page()
248249
while page is not None:
@@ -387,6 +388,8 @@ def _get_next_page_response(self):
387388
388389
:rtype: dict
389390
:returns: The parsed JSON response of the next page's contents.
391+
392+
:raises ValueError: If the HTTP method is not ``GET`` or ``POST``.
390393
"""
391394
params = self._get_query_params()
392395
if self._HTTP_METHOD == 'GET':

core/google/cloud/operation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def register_type(klass, type_url=None):
5050
:param type_url: (Optional) URL naming the type. If not provided,
5151
infers the URL from the type descriptor.
5252
53-
:raises: ValueError if a registration already exists for the URL.
53+
:raises ValueError: if a registration already exists for the URL.
5454
"""
5555
if type_url is None:
5656
type_url = _compute_type_url(klass)
@@ -258,7 +258,7 @@ def poll(self):
258258
259259
:rtype: bool
260260
:returns: A boolean indicating if the current operation has completed.
261-
:raises: :class:`~exceptions.ValueError` if the operation
261+
:raises ValueError: if the operation
262262
has already completed.
263263
"""
264264
if self.complete:

core/nox.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def lint(session):
5050
serious code quality issues.
5151
"""
5252
session.interpreter = 'python3.6'
53-
session.install('flake8', 'pylint', 'gcp-devrel-py-tools')
53+
session.install(
54+
'flake8', 'flake8-import-order', 'pylint', 'gcp-devrel-py-tools')
5455
session.install('.')
5556
session.run('flake8', 'google/cloud/core')
5657
session.run(

0 commit comments

Comments
 (0)